/* Phân hệ Thương mại (24/10/2026) — chỉ lớp tm-*, dùng chung biến màu của styles.css.
   Máy tính (≥1024px): body.tm-desk = menu trái riêng + nội dung rộng (bản chạy thật mặc định là cột điện thoại). */
.tm { --tm-gap: 14px; }
.tm-page { display: grid; gap: var(--tm-gap); grid-template-columns: minmax(0, 1fr); } /* cột co theo màn hình, không giãn theo nội dung dài (nút, mã) */
.tm-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.tm-head h2 { margin: 2px 0 0; font-size: 22px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tm-head .sub { margin-top: 4px; font-size: 13px; color: var(--muted); }
.tm-eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--tm); }
.tm-acts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tm-acts .btn { height: 42px; padding: 0 14px; font-size: 14px; border-radius: 11px; }
.tm-search { display: flex; gap: 8px; flex: 1 1 260px; max-width: 520px; }
.tm-search .input { height: 42px; font-size: 15px; border-radius: 11px; }
.tm-search .btn { height: 42px; }
.tm .card h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; }
.tm .card h3 small { font-size: 12px; font-weight: 700; color: var(--muted); }
.tm-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tm-kpis .kpi .v { font-size: 24px; }
.tm-kpis .kpi .h { margin-top: 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.tm-grid2 { display: grid; gap: var(--tm-gap); grid-template-columns: minmax(0, 1fr); align-items: start; }
.tm-cols { display: grid; gap: var(--tm-gap); grid-template-columns: minmax(0, 1fr); align-items: start; }
.tm-tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.tm-tabs::-webkit-scrollbar { display: none; }
.tm-tabs a { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; color: var(--text); font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.tm-tabs a .n { font-size: 12px; color: var(--muted); font-weight: 800; }
.tm-tabs a.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tm-tabs a.on .n { color: rgba(255,255,255,.8); }
.tm-tabs a.hot:not(.on) { border-color: var(--bad-line); color: var(--bad); background: var(--bad-bg); }

/* Bảng dữ liệu */
.tm-tw { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--sh); }
.tm-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.tm-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 800; text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tm-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--text); }
.tm-table tr:last-child td { border-bottom: 0; }
.tm-table tbody tr.go { cursor: pointer; }
.tm-table tbody tr.go:hover td { background: #FAFAFB; }
.tm-table .num, .tm-table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tm-table .code { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.tm-table .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tm-table tr.late td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.tm-table tfoot td { font-weight: 800; background: var(--surface-2); }
.tm-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.tm-badges .badge { height: 22px; font-size: 11px; padding: 0 8px; }

/* Thanh tiến độ 9 bước */
.tm-steps { display: flex; gap: 0; margin: 0; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
.tm-steps::-webkit-scrollbar { display: none; }
.tm-steps li { flex: 1 0 auto; min-width: 74px; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; font-size: 12px; font-weight: 700; color: var(--faint); text-align: center; }
.tm-steps li::before { content: ""; position: absolute; top: 11px; left: -50%; width: 100%; height: 2px; background: var(--line); z-index: 0; }
.tm-steps li:first-child::before { display: none; }
.tm-steps .d { position: relative; z-index: 1; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line-2); background: #fff; display: grid; place-items: center; }
.tm-steps li.done { color: var(--text); }
.tm-steps li.done .d { background: #12B76A; border-color: #12B76A; color: #fff; }
.tm-steps li.done::before, .tm-steps li.now::before { background: #12B76A; }
.tm-steps li.now { color: var(--ink); font-weight: 800; }
.tm-steps li.now .d { border-color: var(--ink); box-shadow: 0 0 0 4px rgba(16,24,40,.1); }
.tm-steps li.now .d::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.tm-steps .d .i { width: 14px; height: 14px; }
.tm-mini { display: inline-flex; gap: 3px; vertical-align: middle; }
.tm-mini i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); }
.tm-mini i.done { background: #12B76A; }
.tm-mini i.now { background: var(--ink); box-shadow: 0 0 0 2px rgba(16,24,40,.15); }

/* Dòng hàng sửa trực tiếp */
.tm-ed input, .tm-ed select, .tm-in { height: 38px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff; color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; outline: none; width: 100%; box-sizing: border-box; }
.tm-ed input:focus, .tm-ed select:focus, .tm-in:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(16,24,40,.08); }
.tm-ed input.err, .tm-in.err { border-color: var(--bad); background: var(--bad-bg); }
.tm-ed .num input { text-align: right; }
.tm-ed td { padding: 6px 6px; }
.tm-ed td:first-child { padding-left: 10px; }
.tm-x { width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--faint); cursor: pointer; display: grid; place-items: center; }
.tm-x:hover { background: var(--bad-bg); color: var(--bad); }
.tm-thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--faint); cursor: pointer; flex: none; overflow: hidden; }
.tm-thumb img { width: 100%; height: 100%; object-fit: cover; }
label.tm-thumb input { display: none; }
.tm-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tm-photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; background: var(--surface-2); }
.tm-bigimg { width: 100%; max-height: 70dvh; object-fit: contain; border-radius: 12px; background: #000; }
.tm-lcard { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; background: #fff; }
.tm-lcard + .tm-lcard { margin-top: 8px; }
.tm-lcard .row2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.tm-lbl { font-size: 11px; font-weight: 800; color: var(--muted); margin-bottom: 3px; }

/* Tổng tiền, luồng chứng từ, dòng thời gian */
.tm-tot { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 14px; }
.tm-tot dt { color: var(--muted); }
.tm-tot dd { margin: 0; text-align: right; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.tm-tot .big { font-size: 18px; font-weight: 800; }
.tm-tot .sep { grid-column: 1 / -1; border-top: 1px solid var(--line); margin: 4px 0; }
.tm-flow { display: grid; gap: 8px; }
.tm-flow a, .tm-flow .it { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); background: #fff; }
.tm-flow a:hover { border-color: var(--line-2); background: #FAFAFB; }
.tm-flow .k { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tm-flow .t { font-weight: 700; color: var(--ink); }
.tm-flow .s { font-size: 12px; color: var(--muted); }
.tm-tl { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.tm-tl li { display: grid; grid-template-columns: 10px 1fr; gap: 10px; font-size: 13px; }
.tm-tl li::before { content: ""; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--line-2); }
.tm-tl li.duyet::before, .tm-tl li.huy::before { background: var(--bad); }
.tm-tl li.tien::before { background: #12B76A; }
.tm-tl li.ghi_chu::before { background: var(--tm); }
.tm-tl .m { font-size: 12px; color: var(--muted); }
.tm-alerts { display: grid; gap: 8px; }
.tm-al { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; text-decoration: none; color: var(--text); }
.tm-al.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.tm-al.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.tm-al .t { font-weight: 700; color: var(--ink); }
.tm-al .s { font-size: 12px; color: var(--muted); }
.tm-al .act { margin-left: auto; display: flex; gap: 6px; flex: none; }
.tm-al .act .btn { height: 34px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.tm-empty { padding: 18px; text-align: center; font-size: 14px; color: var(--muted); }
.tm-bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.tm-bar span { display: block; height: 100%; background: #12B76A; }
.tm-bar.over span { background: var(--bad); }
.tm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tm-chips button { height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; font-size: 13px; font-weight: 700; color: var(--text); cursor: pointer; }
.tm-chips button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tm-pick { display: grid; gap: 6px; margin-top: 8px; }
.tm-pick button { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; text-align: left; font-size: 14px; }
.tm-pick button:hover { border-color: var(--ink); }
.tm-cust { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--ink); border-radius: 12px; background: #fff; }
.tm-dirty { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); z-index: 24; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: var(--sh-lg); }
.tm-dirty .grow { font-size: 14px; font-weight: 700; }
.tm-dirty .btn { height: 38px; font-size: 14px; }
.tm-sel { display: flex; align-items: center; gap: 10px; }
.tm-sel input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }
.tm-group { background: #fff; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.tm-group + .tm-group { margin-top: 10px; }
.tm-group .gh { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-size: 13px; }
.tm-group .gl { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); }
.tm-group .gl:first-of-type { border-top: 0; }
.tm-mx { font-size: 12px; }
.tm-mx td, .tm-mx th { text-align: center; padding: 6px 8px; }
.tm-mx td:first-child, .tm-mx th:first-child { text-align: left; }
.tm-print { display: none; }
.tm .card + .card { margin-top: 0; } /* bố cục TM dùng grid gap, bỏ lề chồng của styles.css */
/* .label của styles.css đặt margin sau .mt* nên ghi đè mất khoảng cách trên — trả lại cho nhãn trong phân hệ TM */
.tm .label.mt8 { margin-top: 8px; } .tm .label.mt12 { margin-top: 12px; } .tm .label.mt16 { margin-top: 16px; }
.tm-dirty[hidden], .tm [hidden] { display: none !important; }
.tm .tm-mb { margin-bottom: 12px; gap: 8px; }
.tm .code { font-family: var(--mono); }
.tm h2 .code { font-size: 20px; }

/* Bộ sửa dòng hàng: điện thoại = thẻ 3 hàng, máy tính = 1 hàng như bảng tính */
.tm-lines { display: grid; gap: 8px; }
.tm-lh, .tm-lr { display: grid; gap: 6px 8px; align-items: center; }
.tm-lh { font-size: 12px; font-weight: 800; color: var(--muted); padding: 0 10px; }
.tm-lr { grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr) 34px; grid-template-areas: "ph nm nm nm x" "ph sh qt pr ." "ph vt fe am ."; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.tm-lr .ph { grid-area: ph; align-self: start; }
.tm-lr .nm { grid-area: nm; display: grid; gap: 6px; }
.tm-lr .sh { grid-area: sh; } .tm-lr .qt { grid-area: qt; } .tm-lr .pr { grid-area: pr; }
.tm-lr .vt { grid-area: vt; } .tm-lr .fe { grid-area: fe; } .tm-lr .am { grid-area: am; }
.tm-lr .tm-x { grid-area: x; align-self: start; }
.tm-lr input, .tm-lr select { height: 38px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 9px; background: #fff; color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; outline: none; width: 100%; box-sizing: border-box; min-width: 0; }
.tm-lr input:focus, .tm-lr select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(16,24,40,.08); }
.tm-lr input.err { border-color: var(--bad); background: var(--bad-bg); }
.tm-lr .num input { text-align: right; }
.tm-lr .lb { display: block; font-size: 11px; font-weight: 800; color: var(--muted); margin-bottom: 3px; }
.tm-lr .am b { display: block; height: 38px; line-height: 38px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.tm-lr .nm input[data-f="link"] { font-weight: 500; font-size: 13px; color: var(--muted); }
@media (min-width: 720px) {
  .tm-lh, .tm-lr { grid-template-columns: 44px minmax(200px, 2.4fr) 104px 64px 120px 76px 84px 104px 34px; grid-template-areas: "ph nm sh qt pr vt fe am x"; }
  .tm-lr { padding: 8px 10px; }
  .tm-lr .lb { display: none; }
  .tm-lh .num { text-align: right; }
}

@media (min-width: 720px) {
  .tm-grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (min-width: 1024px) {
  body.tm-desk .app { max-width: none; display: grid; grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: auto auto 1fr; box-shadow: none; }
  body.tm-desk .side { display: flex !important; flex-direction: column; grid-column: 1; grid-row: 1 / span 3; align-self: start; position: sticky; top: 0; height: 100dvh; overflow-y: auto; padding: 16px 12px 24px; box-sizing: border-box; background: var(--surface); border-right: 1px solid var(--line); }
  body.tm-desk .topbar, body.tm-desk .demo-strip, body.tm-desk main { grid-column: 2; }
  body.tm-desk .topbar { padding: 0 24px; }
  body.tm-desk .nav { display: none; }
  body.tm-desk main { width: 100%; max-width: 1480px; margin: 0 auto; box-sizing: border-box; padding: 22px 32px 64px; }
  body.tm-desk main.has-sticky { padding-bottom: 120px; }
  body.tm-desk .sticky-actions { left: 248px; transform: none; bottom: 0; width: calc(100vw - 248px); max-width: none; padding: 14px 32px 16px; box-sizing: border-box; }
  body.tm-desk .toast { left: calc(248px + (100vw - 248px) / 2); bottom: 28px; }
  body.tm-desk .sheet-backdrop { align-items: center; }
  body.tm-desk .sheet { max-width: 680px; max-height: 88dvh; border-radius: 20px; padding-bottom: 20px; }
  body.tm-desk .sheet .handle { display: none; }
  body.tm-desk .tm-dirty { bottom: 16px; }
  /* chỉ chia cột khi khung máy tính đã bật (tránh lúc đổi cỡ cửa sổ: cột điện thoại 560px mà lại chia 2 cột) */
  body.tm-desk .tm-cols { grid-template-columns: minmax(0, 1fr) 360px; }
  body.tm-desk .tm-grid2.wide-left { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
  .tm-side-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
  .tm-side-brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--tm); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
  .tm-side-brand b { display: block; font-size: 15px; font-weight: 800; color: var(--ink); }
  .tm-side-brand span { display: block; font-size: 12px; color: var(--muted); }
  .tm-side-new { margin: 6px 0 4px; width: 100%; height: 42px; font-size: 14px; border-radius: 11px; }
  .side-nav a .n { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; }
  .side-nav a .n.bad { background: var(--bad-bg); color: var(--bad); }
  .side-nav a.on .n { background: rgba(255,255,255,.18); color: #fff; }
}
@media (max-width: 719.98px) {
  .tm-head h2 { font-size: 19px; }
  .tm-hide-m { display: none !important; }
  .tm-table { font-size: 13px; }
}
@media (min-width: 720px) {
  .tm-show-m { display: none !important; }
}
@media print {
  body.tm-printing .app, body.tm-printing #overlay, body.tm-printing #toast-host { display: none !important; }
  body.tm-printing .tm-print { display: block !important; padding: 0; font-size: 12pt; color: #000; }
  .tm-print table { width: 100%; border-collapse: collapse; margin: 12pt 0; }
  .tm-print th, .tm-print td { border-bottom: 1px solid #999; padding: 5pt 4pt; text-align: left; }
  .tm-print td.num, .tm-print th.num { text-align: right; }
  .tm-print h1 { font-size: 18pt; margin: 0 0 4pt; }
  .tm-print .muted { color: #444; }
}
