:root {
  /* Bộ màu "Xanh rêu" (Color Hunt: #EDF1D6 #9DC08B #609966 #40513B) */
  --bg: #f5f7ec; --surface: #ffffff; --surface-2: #eef1e2; --border: #dde3c8; --text: #232b20; --muted: #5c6a55;
  --accent: #40513b; --accent-soft: #e3ebcf; --mark: #40513b; --ok: #1e7a46; --ok-soft: #e2f1e3; --warn: #9a6100; --warn-soft: #fbefd6;
  --bad: #b42318; --bad-soft: #fde8e6; --bar: #609966; --shadow: 0 1px 2px rgba(35,43,32,.06); --pop: 0 10px 30px rgba(35,43,32,.16);
  --radius: 12px; --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11140f; --surface: #181d15; --surface-2: #20271c; --border: #2e3828; --text: #e8eedf; --muted: #a0ad94;
    --accent: #9dc08b; --accent-soft: #26331f; --mark: #40513b; --ok: #5cc98a; --ok-soft: #15301f; --warn: #f0b75a; --warn-soft: #3a2c12;
    --bad: #ff8a7a; --bad-soft: #3d1c19; --bar: #87b072; --shadow: none; --pop: 0 10px 30px rgba(0,0,0,.5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11140f; --surface: #181d15; --surface-2: #20271c; --border: #2e3828; --text: #e8eedf; --muted: #a0ad94;
  --accent: #9dc08b; --accent-soft: #26331f; --mark: #40513b; --ok: #5cc98a; --ok-soft: #15301f; --warn: #f0b75a; --warn-soft: #3a2c12;
  --bad: #ff8a7a; --bad-soft: #3d1c19; --bar: #87b072; --shadow: none; --pop: 0 10px 30px rgba(0,0,0,.5); color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; line-height: 1.3; text-wrap: balance; }
h2 { font-size: 16px; margin: 0 0 12px; text-wrap: balance; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ico { width: 20px; height: 20px; flex: none; }

/* ---------- Thanh trên ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-in { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 58px; }
.brand { font-weight: 700; color: var(--text); white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--mark); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; }
.nav a { padding: 8px 11px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-weight: 500; display: inline-flex; align-items: center; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }

/* Ô tìm nhanh */
.qs { position: relative; display: flex; align-items: center; width: 260px; flex: none; }
.qs .ico { position: absolute; left: 10px; color: var(--muted); width: 18px; height: 18px; pointer-events: none; }
.qs input { width: 100%; padding-left: 34px; background: var(--surface-2); border-color: transparent; }
.qs input:focus { background: var(--surface); }
.qs-list { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--pop); overflow: hidden; z-index: 30; }
.qs-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; color: var(--text); border-bottom: 1px solid var(--border); }
.qs-item:last-child { border-bottom: 0; }
.qs-item:hover, .qs-item.sel { background: var(--accent-soft); text-decoration: none; }
.qs-main { display: flex; flex-direction: column; min-width: 0; }
.qs-main b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qs-main small { color: var(--muted); }
.qs-empty { padding: 12px; color: var(--muted); }

/* Menu tài khoản */
.menu { position: relative; flex: none; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; color: var(--text); font-weight: 500; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover, .menu[open] summary { background: var(--surface-2); }
.menu-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--pop); padding: 6px; z-index: 30; }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-head span { color: var(--muted); font-size: 12px; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); text-decoration: none; }
.menu-pop form { margin: 0; }

/* Menu đáy (điện thoại) */
.tabbar { display: none; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head > div { min-width: 0; }
.page-head p { margin: 0; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 4px; font-size: 13px; }

/* ---------- Thẻ ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.grid > .card + .card { margin-top: 0; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mt { margin-top: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: var(--text); min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -.01em; white-space: nowrap; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }
a.kpi:hover { text-decoration: none; border-color: var(--accent); }
@media (max-width: 900px) { .g2, .g3 { grid-template-columns: 1fr; } }

/* ---------- Nhãn, thanh mức dùng ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.meter { display: inline-block; width: 56px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; vertical-align: middle; }
.meter > span { display: block; height: 100%; border-radius: 3px; background: var(--ok); }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }
.meter-pct { font-size: 11px; margin-left: 6px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-pct.bad { color: var(--bad); font-weight: 600; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tfoot td { font-weight: 700; background: var(--surface-2); }
.card .table-wrap { border: 0; border-radius: 0; margin: 0 -16px -16px; }
.card table th:first-child, .card table td:first-child { padding-left: 16px; }
td.name { min-width: 220px; }
td.name a { font-weight: 600; }
td.wide { min-width: 160px; }
.sub-line { display: block; font-size: 12px; color: var(--muted); }
.sortable-th { cursor: pointer; user-select: none; }
.sortable-th:hover { color: var(--text); }
.sortable-th::after { content: "↕"; margin-left: 4px; opacity: .35; font-size: 11px; }
.sortable-th[data-dir="asc"]::after { content: "↑"; opacity: 1; }
.sortable-th[data-dir="desc"]::after { content: "↓"; opacity: 1; }

/* ---------- Biểu mẫu ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.filters .grow { flex: 1 1 260px; }
.filters .grow input { width: 100%; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 40px; max-width: 100%; }
textarea { min-height: 70px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 8px 14px; min-height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn.primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.btn.bad { background: var(--surface); border-color: var(--bad); color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.form-grid label, .field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid label.check, label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { min-height: 0; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; white-space: nowrap; }
.chip:hover { text-decoration: none; color: var(--text); border-color: var(--muted); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.chip b { margin-left: 4px; }

/* ---------- Thông báo nhanh ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.notice { background: var(--surface-2); border-radius: 8px; padding: 10px 14px; color: var(--muted); font-size: 13px; }

/* ---------- Thẻ quyết định đi hàng, gợi ý ---------- */
.verdict { border-radius: var(--radius); padding: 16px 18px; display: flex; gap: 14px; align-items: flex-start; }
.verdict.ok { background: var(--ok-soft); }
.verdict.bad { background: var(--bad-soft); }
.verdict .big { font-size: 19px; font-weight: 800; letter-spacing: .01em; line-height: 1.3; }
.verdict.ok .big { color: var(--ok); }
.verdict.bad .big { color: var(--bad); }
.verdict ul { margin: 6px 0 0; padding-left: 18px; }
.verdict .icon { font-size: 24px; line-height: 1.2; }
.tips { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tips li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.tips li .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--accent); }
.tips li.bad .dot { background: var(--bad); }
.tips li.warn .dot { background: var(--warn); }
.tips li.ok .dot { background: var(--ok); }
.tips li b { font-variant-numeric: tabular-nums; }

/* Việc cần làm hôm nay */
.todo { list-style: none; margin: 0; padding: 0; }
.todo li + li { border-top: 1px solid var(--border); }
.todo a { display: flex; align-items: center; gap: 12px; padding: 11px 4px; color: var(--text); }
.todo a:hover { text-decoration: none; background: var(--surface-2); }
.todo .n { flex: none; min-width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 15px; background: var(--accent-soft); color: var(--accent); padding: 0 6px; }
.todo .bad .n { background: var(--bad-soft); color: var(--bad); }
.todo .warn .n { background: var(--warn-soft); color: var(--warn); }
.todo .t { flex: 1; min-width: 0; }
.todo .t b { display: block; font-weight: 600; }
.todo .t span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo .ico { color: var(--muted); width: 18px; height: 18px; }
.all-clear { display: flex; gap: 10px; align-items: center; color: var(--ok); font-weight: 600; padding: 6px 2px; }

/* Thanh tuổi nợ */
.aging-row { display: grid; grid-template-columns: 150px 1fr 110px; gap: 10px; align-items: center; padding: 6px 0; }
.aging-row .track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.aging-row .fill { height: 100%; background: var(--bar); border-radius: 5px; }
.aging-row .fill.b3 { opacity: .75; } .aging-row .fill.b4 { background: var(--warn); } .aging-row .fill.b5 { background: var(--bad); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.list li:last-child { border-bottom: 0; }
.list li > span:first-child { min-width: 0; }
.empty { color: var(--muted); padding: 8px 0; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 12px; }
.item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: baseline; }

/* Đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* ---------- Máy tính bảng: thu gọn thanh trên ---------- */
@media (max-width: 1180px) {
  .qs { width: 200px; }
  .menu-name { display: none; }
}

/* ---------- Điện thoại ---------- */
@media (max-width: 820px) {
  .topbar-in { height: 56px; gap: 10px; }
  .nav, .brand-name { display: none; }
  .qs { flex: 1; width: auto; }
  .qs-list { min-width: 0; position: fixed; left: 8px; right: 8px; top: 60px; }
  body.in main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; color: var(--muted); font-size: 11px; font-weight: 500; border-radius: 10px; }
  .tabbar a.on { color: var(--accent); }
  .tabbar a.on .ico { background: var(--accent-soft); border-radius: 10px; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar .ico { width: 44px; height: 28px; padding: 3px 12px; }
  .tabbar .count { position: absolute; top: 2px; left: calc(50% + 8px); margin: 0; }
}
@media (max-width: 720px) {
  main { padding: 14px 12px 40px; }
  h1 { font-size: 19px; }
  .page-head { margin-bottom: 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .value { font-size: 19px; }
  .card { padding: 14px; }
  .card .table-wrap { margin: 0 -14px -14px; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .grow, .filters .full { grid-column: 1 / -1; }
  .filters label select, .filters label input { width: 100%; }
  .filters .btn { grid-column: 1 / -1; }
  .aging-row { grid-template-columns: 1fr 100px; }
  .aging-row .track { grid-column: 1 / -1; grid-row: 2; }

  /* Bảng có class rt → mỗi dòng thành một thẻ, ô có nhãn bên trái */
  .table-wrap:has(> table.rt) { border: 0; background: none; overflow: visible; }
  .card .table-wrap:has(> table.rt) { margin: 0; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt thead { display: none; }
  table.rt tfoot { display: block; }
  table.rt tfoot tr { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
  table.rt tfoot td { display: none; padding: 0; border: 0; background: none; }
  table.rt tfoot td[data-label] { display: block; }
  table.rt tfoot td[data-label]::before { content: attr(data-label) ": "; font-weight: 500; color: var(--muted); }
  table.rt tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .card table.rt tbody tr { box-shadow: none; }
  table.rt tbody tr:hover td { background: none; }
  table.rt td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; min-width: 0 !important; }
  table.rt td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; white-space: nowrap; }
  table.rt td.lead { display: block; text-align: left; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
  table.rt td.lead::before { content: none; }
  table.rt td.full { display: block; text-align: left; }
  table.rt td.full::before { display: block; margin-bottom: 2px; }
  table.rt td.hide-m, table.rt td:empty { display: none; }
  table.rt td.num { white-space: normal; }
  .card table.rt th:first-child, .card table.rt td:first-child { padding-left: 0; }
  table.rt tr.empty-row td { display: block; text-align: center; }
}

/* Duyệt đi hàng */
.decide { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.decide input { flex: 1 1 220px; }
@media (max-width: 720px) { .decide .btn { flex: 1; } }

/* ---------- Điện thoại: thẻ gọn ---------- */
@media (max-width: 720px) {
  .kpis > .kpi:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
  .todo .t span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .todo .n { min-width: 44px; }
  /* Ô xếp thành lưới 2–3 cột: nhãn nhỏ ở trên, giá trị ở dưới */
  table.rt tbody tr { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px 12px; }
  table.rt td { display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 0; text-align: left; padding: 0; }
  table.rt td::before { font-size: 11px; line-height: 1.4; }
  table.rt td.lead, table.rt td.full { grid-column: 1 / -1; }
  table.rt td.lead { padding-bottom: 6px; margin-bottom: 0; }
  table.rt td.num { white-space: nowrap; font-weight: 600; }
  table.rt td .sub-line { white-space: normal; }
  table.rt td .meter { margin-top: 5px; }
  table.rt td .badge { margin-top: 1px; }
  table.rt td:has(> .btn) { grid-column: 1 / -1; align-items: stretch; }
  table.rt td > .btn { width: 100%; }
}
@media (max-width: 720px) {
  table.rt td:has(> .badge) { grid-column: span 2; }
  table.rt td .badge { white-space: normal; max-width: 100%; }
}
.filters label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
@media (max-width: 720px) {
  .filters label.check { grid-column: 1 / -1; min-height: 32px; }
  table.rt td::before { white-space: normal; }
}
.filters label.check input { width: auto !important; min-height: 0; margin: 0; }

/* Nút xóa (dòng hạn mức, hợp đồng): gọn, màu đỏ, mở ra mới thấy ô lý do */
details.del { margin-top: 6px; }
details.del > summary { color: var(--bad); font-weight: 500; font-size: 12px; }
details.del[open] > summary { margin-bottom: 6px; }
details.del .filters { margin: 0; }
details.del input { flex: 1 1 180px; min-height: 34px; }
.card details.del > summary { font-size: 14px; }

/* Tiêu đề bảng dính dưới thanh menu (app.js dời ô xuống khi kéo trang) */
thead th { position: relative; z-index: 3; }
thead th.stuck { box-shadow: inset 0 -1px 0 var(--border), 0 6px 8px -6px rgba(16,24,40,.25); }

/* Cột đầu (tên khách / số HĐ) đứng yên khi kéo ngang bảng rộng — chỉ ở dạng bảng, không áp cho thẻ điện thoại */
@media (min-width: 721px) {
  .table-wrap > table th:first-child, .table-wrap > table td:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface); }
  .table-wrap > table th:first-child { z-index: 4; background: var(--surface-2); }
  .table-wrap > table tfoot td:first-child { background: var(--surface-2); }
  .table-wrap > table tbody tr:hover td:first-child { background: var(--surface-2); }
  .table-wrap.scrolled > table th:first-child, .table-wrap.scrolled > table td:first-child { box-shadow: 1px 0 0 var(--border), 6px 0 8px -6px rgba(16,24,40,.2); }
}

/* Thanh tuổi nợ nóng dần: chưa đến hạn xanh → quá hạn nhẹ xanh nhạt → vàng nhạt → vàng → đỏ */
.aging-row .fill.b1 { background: var(--bar); opacity: 1; }
.aging-row .fill.b2 { background: var(--bar); opacity: .55; }
.aging-row .fill.b3 { background: var(--warn); opacity: .55; }
.aging-row .fill.b4 { background: var(--warn); opacity: 1; }
.aging-row .fill.b5 { background: var(--bad); opacity: 1; }

/* Logo AKUBA: chữ tô theo màu chữ của nền (đen trên nền sáng, trắng trên nền tối) */
.logo-akuba { display: block; height: 17px; width: auto; color: var(--text); flex: none; }
.brand { gap: 10px; }
.brand-sep { width: 1px; height: 20px; background: var(--border); flex: none; }
.brand-name { font-weight: 600; color: var(--accent); }
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.login-brand .logo-akuba { height: 26px; }
.login-brand span { font-weight: 700; color: var(--accent); letter-spacing: .02em; }
@media (max-width: 1180px) and (min-width: 821px) { .brand-sep, .brand-name { display: none; } }
@media (max-width: 820px) { .logo-akuba { height: 14px; } .brand-sep { display: none; } }
