/* finance-vat – Hóa đơn VAT (vt-) và Đồng bộ CRM (sy-) */

/* ---- Danh sách hóa đơn */
.vt-tips:empty { display: none; }
.vt-tips .cu-tip > div { min-width: 0; }
.vt-view button { padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.vt-sumline { margin: 0 0 8px 2px; }
.vt-row { display: grid; grid-template-columns: 34px minmax(240px, 2.6fr) 150px 140px 130px 120px 110px; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.vt-row:hover { background: #f8fafd; }
.vt-row.on { background: #eef4ff; }
.vt-row.off { opacity: .6; }
.vt-row.cm-head, .vt-prow.cm-head { cursor: default; }
.vt-row .num, .vt-prow .num { text-align: right; font-variant-numeric: tabular-nums; }
.vt-main { min-width: 0; }
.vt-main .cm-flags { align-items: center; }
.vt-cust { font-weight: 600; text-decoration: none; }
.vt-err { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.vt-act { text-align: right; }
.vt-act .btn { white-space: nowrap; }
.vt-prow { display: grid; grid-template-columns: 34px minmax(240px, 2.6fr) 150px 150px 140px 120px; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.vt-prow.on { background: #eef4ff; }
.vt-sum tfoot td { border-top: 2px solid var(--line); background: var(--surface-2); }
.cm-bulk .btn[disabled] { opacity: .45; cursor: not-allowed; }

@media (max-width: 1250px) {
  .vt-row { grid-template-columns: 34px minmax(0, 1fr) 140px 130px 110px; }
  .vt-row > :nth-child(4), .vt-row > :nth-child(6) { display: none; }
  .vt-prow { grid-template-columns: 34px minmax(0, 1fr) 130px 130px 120px 110px; }
}
@media (max-width: 760px) {
  .vt-row.cm-head, .vt-prow.cm-head { display: none; }
  .vt-row { grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-areas: "ck main main" ". no total" ". act act"; row-gap: 6px; padding: 12px; }
  .vt-row > .cm-ck { grid-area: ck; align-self: start; padding-top: 2px; }
  .vt-row > .vt-main { grid-area: main; }
  .vt-row > :nth-child(3) { grid-area: no; }
  .vt-row > :nth-child(5) { grid-area: total; }
  .vt-row > .vt-act { grid-area: act; text-align: left; }
  .vt-row > .vt-act:empty { display: none; }
  .vt-prow { grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-areas: "ck main main" ". basis amt" ". items act"; row-gap: 6px; padding: 12px; }
  .vt-prow > .cm-ck { grid-area: ck; align-self: start; }
  .vt-prow > .vt-main { grid-area: main; }
  .vt-prow > :nth-child(3) { grid-area: basis; }
  .vt-prow > :nth-child(4) { grid-area: items; }
  .vt-prow > :nth-child(5) { grid-area: amt; }
  .vt-prow > .vt-act { grid-area: act; }
  .vt-view { width: 100%; }
  .vt-view button { flex: 1; }
  .cm-filters select { flex: 1; min-width: 0; }
}

/* ---- Tạo yêu cầu */
.vt-res { display: grid; gap: 4px; margin: 6px 0; }
.vt-res:empty { display: none; }
.vt-pick { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; font: inherit; cursor: pointer; color: var(--text); }
.vt-pick:hover { border-color: var(--brand-2); background: #f5f9ff; }
.vt-nc { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 10px 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
.vt-items { border: 1px solid var(--line); border-radius: 10px; max-height: 46vh; overflow: auto; }
.vt-item { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.vt-item:first-child { border-top: 0; }
.vt-item-h { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
.vt-item input { width: 16px; height: 16px; }
.vt-ntot { display: flex; gap: 12px; align-items: baseline; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; font-size: 14px; }
.vt-ntot b { font-size: 20px; }

/* ---- Chi tiết */
.vt-ico { width: 56px; height: 56px; border-radius: 14px; display: grid; place-items: center; font-size: 28px; background: var(--surface-2); border: 1px solid var(--line); }
.vt-ico.green { background: #ecfdf5; border-color: #a7f3d0; }
.vt-ico.amber { background: #fffbeb; border-color: #fde68a; }
.vt-ico.red { background: #fef2f2; border-color: #fecaca; }
.vt-ico.blue { background: #eff6ff; border-color: #bfdbfe; }
.vt-big { font-size: 18px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.vt-steps { margin-top: 14px; padding: 12px 16px; }
.vt-steps .pb-steps li small { font-weight: 400; }
.cm-kpis.vt-k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.vt-paper { position: relative; overflow: hidden; border-top: 4px solid var(--brand); }
.vt-paper.draft::after { content: 'NHÁP'; position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg); font-size: 96px; font-weight: 900; color: rgb(2 35 82 / 5%); letter-spacing: .1em; pointer-events: none; }
.vt-paper.void::after { content: 'ĐÃ HỦY'; color: rgb(220 38 38 / 8%); }
.vt-ph { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; border-bottom: 1px dashed var(--line); padding-bottom: 10px; }
.vt-pt { font-weight: 800; font-size: 17px; letter-spacing: .03em; color: var(--brand); }
.vt-pn { text-align: right; line-height: 1.6; }
.vt-parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding: 12px 0; }
.vt-parties > div { min-width: 0; word-break: break-word; }
.vt-lines th { font-size: 12px; }
.vt-lines td:first-child { width: 36px; }
.vt-lines td:nth-child(3) { white-space: nowrap; }
.vt-ptot { display: grid; gap: 4px; margin: 10px 0 0 auto; max-width: 380px; font-size: 14px; }
.vt-ptot > div { display: flex; justify-content: space-between; gap: 12px; }
.vt-ptot b { font-variant-numeric: tabular-nums; }
.vt-grand { border-top: 1px solid var(--line); padding-top: 6px; font-size: 16px; }
.vt-grand b { color: var(--brand); }
.vt-words { margin: 10px 0 0; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.vt-code { font-size: 12px; word-break: break-all; }
.vt-files { display: grid; gap: 8px; }
.vt-file { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: inherit; }
.vt-file:hover { border-color: var(--brand-2); background: #f5f9ff; }
.vt-file > span { font-size: 24px; }
.vt-tl { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.vt-tl li { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px; position: relative; padding-bottom: 12px; font-size: 13px; }
.vt-tl li:not(:last-child)::before { content: ''; position: absolute; left: 13px; top: 26px; bottom: 0; width: 2px; background: var(--line); }
.vt-tl-ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; }
.vt-tl li > div { min-width: 0; word-break: break-word; }

@media (max-width: 760px) {
  .cm-kpis.vt-k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .vt-k3 .cm-kpi { padding: 10px; }
  .vt-k3 .cm-kpi b { font-size: 15px; }
  .vt-k3 .cm-kpi span { font-size: 10.5px; }
  .vt-parties { grid-template-columns: minmax(0, 1fr); }
  .vt-paper.draft::after { font-size: 60px; }
  .vt-ico { width: 44px; height: 44px; font-size: 22px; }
  .vt-lines th:nth-child(3), .vt-lines td:nth-child(3), .vt-lines th:nth-child(4), .vt-lines td:nth-child(4) { display: none; }
  .vt-lines th, .vt-lines td { padding: 6px 4px; font-size: 12.5px; }
  .vt-tips .cu-tip:nth-child(n+4) { display: none; }
  #vt-q, #sy-q { flex: 1 1 100%; }
  .vt-steps .pb-steps { gap: 6px 12px !important; }
}

/* ---- Đồng bộ CRM */
.sy-health { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: center; border-left: 5px solid var(--line); margin-bottom: 14px; }
.sy-health.ok { border-left-color: var(--ok); }
.sy-health.warn { border-left-color: #f59e0b; }
.sy-health.bad { border-left-color: var(--danger); }
.sy-health.off { border-left-color: var(--silver); }
.sy-dot { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--surface-2); }
.sy-health.ok .sy-dot { background: #ecfdf5; }
.sy-health.warn .sy-dot { background: #fffbeb; }
.sy-health.bad .sy-dot { background: #fef2f2; }
.sy-hmain { min-width: 0; }
.sy-hmain > b { font-size: 16px; }
#sy-test-res:not(:empty) { margin-top: 6px; }
#sy-test-res .pill { white-space: normal; }
.sy-facts { display: flex; gap: 22px; margin: 0; }
.sy-facts > div { min-width: 0; }
.sy-facts dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.sy-facts dd { margin: 2px 0 0; font-size: 13px; word-break: break-word; }
.sy-2 { margin-top: 2px; }
.sy-leg { font-size: 12px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.sy-leg i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }
.sy-leg i.ok, .sy-stack i.ok { background: var(--accent); }
.sy-leg i.bad, .sy-stack i.bad { background: var(--danger); }
.sy-chart { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; height: 215px; margin-top: 12px; align-items: end; }
.sy-col { display: grid; grid-template-rows: minmax(0, 1fr) auto auto; height: 100%; text-align: center; gap: 2px; }
.sy-stack { display: flex; flex-direction: column; justify-content: flex-end; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.sy-stack i { display: block; width: 100%; min-height: 0; }
.sy-col b { font-size: 12px; font-variant-numeric: tabular-nums; min-height: 15px; }
.sy-col span { font-size: 11px; color: var(--muted); }
.sy-errs { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; max-height: 230px; overflow: auto; }
.sy-errs li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.sy-emsg code { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--danger); }
.sy-en { font-size: 18px; font-variant-numeric: tabular-nums; }
.sy-eact { display: flex; gap: 4px; }
.sy-sd { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--silver); }
.sy-sd.green { background: var(--ok); } .sy-sd.red { background: var(--danger); } .sy-sd.amber { background: #f59e0b; } .sy-sd.blue { background: var(--brand-2); }
.cu-seg.on .sy-sd { box-shadow: 0 0 0 2px rgb(255 255 255 / 60%); }
.sy-row { display: grid; grid-template-columns: 34px minmax(220px, 2fr) 140px 120px minmax(180px, 1.6fr) 110px; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.sy-row:hover { background: #f8fafd; }
.sy-row.on { background: #eef4ff; }
.sy-row.cm-head { cursor: default; }
.sy-ev { display: flex; gap: 10px; align-items: center; min-width: 0; }
.sy-ico { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-size: 16px; }
.sy-stc { min-width: 0; }
.sy-err { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.sy-act { display: flex; gap: 4px; justify-content: flex-end; }
.sy-act .btn { white-space: nowrap; }
/* Xem sự kiện */
.sy-ev-head .cd-dl { grid-template-columns: 100px minmax(0, 1fr); }
.sy-tabs { margin-top: 12px; }
.sy-jtools { margin: 4px 0 8px; gap: 6px; }
.sy-json { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 12px 14px; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 52vh; overflow: auto; }
.sy-json pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: #fca5a5; }
.sy-json details { padding-left: 14px; }
.sy-json > details { padding-left: 0; }
.sy-json summary { cursor: pointer; list-style: none; margin-left: -12px; }
.sy-json summary::-webkit-details-marker { display: none; }
.sy-json summary::before { content: '▸'; display: inline-block; width: 12px; color: #64748b; }
.sy-json details[open] > summary::before { content: '▾'; }
.sy-json .jl { padding-left: 14px; word-break: break-word; }
.sy-json .jk { color: #93c5fd; }
.sy-json .js { color: #86efac; }
.sy-json .jnum { color: #fcd34d; }
.sy-json .jb { color: #f9a8d4; }
.sy-json .jnull { color: #94a3b8; font-style: italic; }
.sy-json .jp { color: #64748b; }

@media (max-width: 1100px) {
  .sy-health { grid-template-columns: auto minmax(0, 1fr); }
  .sy-facts { grid-column: 1 / -1; flex-wrap: wrap; gap: 12px 22px; }
  .sy-row { grid-template-columns: 34px minmax(0, 1fr) 130px minmax(160px, 1.3fr) 100px; }
  .sy-row > :nth-child(4) { display: none; }
}
@media (max-width: 760px) {
  .sy-health { gap: 10px; }
  .sy-dot { width: 40px; height: 40px; font-size: 18px; }
  .sy-facts > div { flex: 1 1 40%; }
  .sy-chart { gap: 5px; height: 140px; }
  .sy-errs li { grid-template-columns: minmax(0, 1fr) auto; }
  .sy-eact { grid-column: 1 / -1; }
  .sy-row.cm-head { display: none; }
  .sy-row { grid-template-columns: 28px minmax(0, 1fr) auto; grid-template-areas: "ck ev act" ". st st" ". time time"; row-gap: 6px; padding: 12px; }
  .sy-row > .cm-ck { grid-area: ck; align-self: start; padding-top: 6px; }
  .sy-row > .sy-ev { grid-area: ev; }
  .sy-row > :nth-child(3) { grid-area: time; }
  .sy-row > .sy-stc { grid-area: st; }
  .sy-row > .sy-act { grid-area: act; align-self: start; }
  .sy-act [data-view] { font-size: 0; padding: 6px 8px; }
  .sy-act [data-view]::before { content: '👁'; font-size: 14px; }
}

/* ---- Sửa hóa đơn / mẫu hóa đơn (vat-editor.js) */
.ve-grid, .ve-tpl-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.ve-left, .ve-tpl-f { display: grid; gap: 12px; min-width: 0; }
.ve-tpl-f .field input, .ve-sec .field input, .ve-sec .field select, .ve-tpl-f .field select { width: 100%; }
.ve-sec { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--surface); }
.ve-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.ve-2 .ve-full { grid-column: 1 / -1; }
.ve-3 { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 10px; }
.ve-seg { justify-self: start; }
.ve-lines { display: grid; gap: 8px; }
.ve-lh, .ve-line { display: grid; grid-template-columns: minmax(0, 1fr) 80px 56px 150px 30px; gap: 6px; align-items: start; }
.ve-lh { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ve-line textarea, .ve-line input { width: 100%; padding: 6px 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.ve-line input[data-k="amount"], .ve-line input[data-k="quantity"] { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.ve-line small { display: block; font-size: 10.5px; text-align: right; margin-top: 2px; }
.ve-line textarea:focus, .ve-line input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgb(11 74 158 / 12%); }
.ve-total { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.ve-total.ok { background: #ecfdf5; color: #065f46; }
.ve-total.bad { background: #fef2f2; color: #991b1b; }
.ve-vars { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ve-vars .chip { font: 600 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 8px; }
.ve-paper { position: sticky; top: 0; margin: 0; font-size: 12.5px; }
.ve-paper[data-wm="MẪU"]::after { content: 'MẪU'; }
.ve-paper { position: relative; }
#ve-prev { min-width: 0; }
@media (max-width: 900px) {
  .ve-grid, .ve-tpl-grid { grid-template-columns: 1fr; }
  .ve-paper { position: static; }
}
@media (max-width: 560px) {
  .ve-2, .ve-3 { grid-template-columns: 1fr; }
  .ve-lh { display: none; }
  .ve-line { grid-template-columns: 1fr 1fr 30px; grid-template-areas: "name name del" "unit qty qty" "amt amt amt"; }
  .ve-line textarea { grid-area: name; } .ve-line [data-k="unit"] { grid-area: unit; } .ve-line [data-k="quantity"] { grid-area: qty; }
  .ve-line > div { grid-area: amt; } .ve-line [data-del] { grid-area: del; }
}
.ve-form .field input, .ve-tpl .field input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px; background: var(--surface); }
.ve-form .field input:focus, .ve-tpl .field input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgb(11 74 158 / 12%); }
.ve-form .field > span, .ve-tpl .field > span { font-size: 12.5px; }
