:root {
  --primary: #0088ff;
  --primary-dark: #006fd6;
  --primary-soft: #e6f3ff;
  --sidebar: #182537;
  --sidebar-hover: #223450;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #e53935;
  --danger-soft: #fdecec;
  --success: #0f9d58;
  --success-soft: #e7f6ee;
  --warning: #f59e0b;
  --warning-soft: #fff6e0;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--sidebar); color: #c9d3e0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid #263852; }
.logo {
  width: 36px; height: 36px; border-radius: 8px; background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 700;
}
.brand-name { color: #fff; font-weight: 600; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: #8a9ab0; }
.nav { padding: 8px 0 24px; }
.nav .sec { padding: 16px 18px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6f819a; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; color: inherit; text-decoration: none;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--primary); }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.top-date { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; }
.view { padding: 20px 24px 40px; max-width: 1400px; width: 100%; }
.spacer { flex: 1; }

/* ---------- Cards / stats ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.06); margin-bottom: 16px; }
.card.pad { padding: 20px; }
.card h3 { font-size: 15px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 1px 2px rgba(0,0,0,.06); border-top: 3px solid var(--primary); }
.stat.orange { border-top-color: var(--warning); }
.stat.green { border-top-color: var(--success); }
.stat.red { border-top-color: var(--danger); }
.stat.purple { border-top-color: #7c4dff; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.grid-2col { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.chart { padding: 8px 18px 14px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover { fill: var(--primary-dark); }
.chart text { font-size: 11px; fill: var(--muted); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar input, .toolbar select { height: 36px; }
input, select, textarea {
  border: 1px solid #d1d5db; border-radius: 6px; padding: 7px 10px; background: #fff; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,136,255,.15); }
textarea { resize: vertical; min-height: 64px; }
input.search { min-width: 280px; flex: 0 1 360px; }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.date-range { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid #d1d5db; background: #fff; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f3b4b2; }
.btn.danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; padding: 4px 8px; border-radius: 4px; }
.icon-btn:hover { background: #f3f4f6; color: var(--danger); }
.row-btns { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8fafc; font-weight: 600; color: #4b5563; font-size: 13px; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f5faff; }
tfoot td { font-weight: 700; background: #f8fafc; }
.r { text-align: right; }
.c { text-align: center; }
.nowrap { white-space: nowrap; }
td.code, .code { color: var(--primary); font-weight: 500; white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.danger { color: var(--danger); }
.success { color: var(--success); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge.blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.yellow { background: var(--warning-soft); color: #b45309; }
.badge.gray { background: #f1f2f4; color: var(--muted); }
.badge.purple { background: #f1ebff; color: #6d3fd6; }
.badge.orange { background: #fff1e6; color: #c2410c; }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: #eef0f3; color: var(--muted); font-size: 12px; margin-left: 4px; }
.tab.active .tab-count { background: var(--primary); color: #fff; }
.hint.warn { background: var(--warning-soft); border-color: #f5d48a; color: #92400e; }
.hint.danger { background: var(--danger-soft); border-color: #f3b4b2; }

/* ô tick chốt đơn */
.win-box { display: inline-flex; cursor: pointer; padding: 4px; }
.win-box input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--success); }
.modal label.win-check { background: var(--success-soft); border: 1px dashed var(--success); border-radius: 8px; padding: 10px 14px; margin-top: 6px; color: #065f46; align-items: center; }
.modal label.win-check input { width: 18px; height: 18px; accent-color: var(--success); }
.modal label.win-check.big { margin-top: 14px; }

/* các bước điều phối đơn hàng */
.steps { display: flex; gap: 4px; margin-bottom: 16px; overflow-x: auto; }
.step { flex: 1; min-width: 96px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 3px; position: relative; padding-top: 2px; }
.step::before { content: ''; position: absolute; top: 15px; left: -50%; width: 100%; height: 2px; background: var(--border); z-index: 0; }
.step:first-child::before { display: none; }
.step.done::before { background: var(--success); }
.step i { font-style: normal; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: #eef0f3; color: var(--muted); font-weight: 700; font-size: 13px; }
.step.done i { background: var(--success); color: #fff; }
.step.next i { background: var(--primary); color: #fff; box-shadow: 0 0 0 4px var(--primary-soft); }
.step b { font-size: 12px; font-weight: 600; }
.step small { font-size: 11px; color: var(--muted); }
.steps.cancelled { opacity: .45; }
.step.failed i { background: var(--danger); color: #fff; }
.step.failed::before { background: var(--danger); }
.step.failed b { color: var(--danger); }


.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

/* ---------- Modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal-wrap[hidden] { display: none; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.modal-foot:empty { display: none; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 14px; }
.modal label.check { flex-direction: row; font-weight: 400; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.card .grid3 label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; margin-bottom: 14px; }
.hint { background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 14px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 20px; margin-bottom: 16px; }
.info-grid div span { display: block; color: var(--muted); font-size: 12px; }
.section-title { font-weight: 600; margin: 18px 0 8px; }

/* line editor */
.line-editor { margin-bottom: 16px; }
.line-editor input.search { width: 100%; max-width: none; margin-bottom: 10px; }
.line-editor .empty { border: 1px dashed #d1d5db; border-radius: 6px; }
table.lines td, table.lines th { padding: 8px 10px; }
table.lines td:first-child { min-width: 200px; }
input.num { width: 90px; text-align: right; padding: 5px 8px; }
input.num.w { width: 130px; }
.summary { background: #f8fafc; border-radius: 8px; padding: 12px 16px; align-self: start; }
.sum-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 0; }
.sum-row.total { font-size: 16px; border-top: 1px dashed #d1d5db; margin-top: 4px; padding-top: 10px; }
.sum-row select { width: 150px; }
.sum-row input.reason { flex: 1; border-color: #f3b4b2; }
.sum-row input.reason:focus { border-color: var(--primary); }
.totals { margin-left: auto; max-width: 340px; margin-top: 12px; }

/* custom fields: List & Hình ảnh */
.modal .field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 14px; }
.field.full, .span-all { grid-column: 1 / -1; }
.contents { display: contents; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; border: 1px solid #d1d5db; border-radius: 6px; padding: 5px 6px; min-height: 38px; cursor: text; background: #fff; }
.chips:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,136,255,.15); }
.chips input { border: 0; box-shadow: none !important; flex: 1; min-width: 140px; padding: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.chip button { border: 0; background: none; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; padding: 0; }
.chip button:hover { color: var(--danger); }
.img-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb { position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #f8fafc; }
.thumb.is-cover { border: 2px solid var(--primary); }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb button { position: absolute; top: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; line-height: 22px; padding: 0; }
.thumb .t-del { right: 4px; }
.thumb .t-main { left: 4px; }
.thumb button:hover { background: var(--primary); }
.thumb .t-del:hover { background: var(--danger); }
.add-img { width: 96px; height: 96px; border: 2px dashed #cbd5e1; border-radius: 8px; background: #fff; color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1.5; }
.add-img:hover { border-color: var(--primary); color: var(--primary); }
img.mini { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); vertical-align: middle; cursor: zoom-in; }
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 70; cursor: zoom-out; padding: 20px; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* bộ lọc chọn nhiều sản phẩm */
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.line-editor .search-row input.search { margin-bottom: 0; flex: 1; }
#pk-toggle.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.picker { border: 1px solid var(--primary); border-radius: 10px; background: #fbfdff; padding: 12px 14px; margin-bottom: 12px; box-shadow: 0 4px 14px rgba(0,136,255,.08); }
.pk-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
.pk-f { display: flex; flex-direction: column; gap: 5px; }
.pk-f.wide { grid-column: 1 / -1; }
.pk-f > span { font-size: 12px; font-weight: 600; color: #4b5563; }
.pk-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pk-chip { border: 1px solid #d1d5db; background: #fff; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.pk-chip:hover { border-color: var(--primary); }
.pk-chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.pk-range { display: flex; align-items: center; gap: 6px; }
.pk-range input { width: 100%; min-width: 0; }
.pk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0 8px; }
.pk-bar .muted { flex: 1; }
.pk-results { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.pk-results thead th { position: sticky; top: 0; z-index: 1; }
.pk-results tr.picked { background: var(--primary-soft); }
.pk-results input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.pk-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.pk-foot .muted { flex: 1; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 860px) { .search-row { flex-direction: column; } }

/* công thức */
input.formula { background: #f3f7fb; font-weight: 600; color: var(--primary-dark); cursor: default; }
input.formula.err { color: var(--danger); font-weight: 400; font-size: 12px; }
input.formula-edit { min-width: 240px; font-family: Consolas, monospace; font-size: 13px; }
#fd-formula { font-family: Consolas, monospace; }
.var-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; }
button.chip { border: 1px solid transparent; cursor: pointer; font-family: inherit; }
button.chip:hover { border-color: var(--primary); }
button.chip.builtin { background: var(--primary); color: #fff; }
button.chip.fn { background: #f1f2f4; color: #374151; font-family: Consolas, monospace; }
.formula-help { background: #f8fafc; border-radius: 8px; padding: 4px 12px 10px; margin-bottom: 14px; }
.formula-help .section-title { margin-top: 8px; }

/* trường sản phẩm hiện bên đơn hàng */
.p-extra { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.p-extra b { color: var(--text); font-weight: 500; }
.p-extra img.mini { width: 34px; height: 34px; }

/* địa chỉ giao hàng */
.addr-list { display: flex; flex-direction: column; gap: 6px; font-weight: 400; }
.addr-list .muted { margin-top: 2px; }
.addr { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.addr b { font-weight: 500; }
.addr span { color: var(--muted); font-size: 12px; }
.addr:hover { border-color: var(--primary); }
.addr.active { border-color: var(--primary); background: var(--primary-soft); }
.addr.hi { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,136,255,.2); }
.addr-scroll { display: flex; flex-direction: column; gap: 6px; max-height: 330px; overflow-y: auto; padding: 2px; }
.link-btn { align-self: flex-start; border: 0; background: none; color: var(--primary); cursor: pointer; padding: 4px 0; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }
.addr-line { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- v2: module / tab con / form theo cấu hình ---------- */
.modal.xwide { max-width: 1240px; }
.user-pick { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }
.user-pick select { height: 32px; font-size: 13px; max-width: 220px; }
a.tab { text-decoration: none; display: inline-block; }
.ftabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: -4px 0 16px; overflow-x: auto; }
.ftab { border: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.ftab.active { color: var(--primary); border-bottom-color: var(--primary); }
.fpanel { min-height: 120px; }
.modal .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; margin-bottom: 14px; }
.flabel { font-weight: 500; color: #374151; }
.req { color: var(--danger); font-weight: 600; }
.computed { background: #f3f7fb; border: 1px dashed #cbd5e1; border-radius: 6px; padding: 8px 10px; min-height: 36px; color: var(--primary-dark); font-weight: 500; }
.mchips { display: flex; flex-wrap: wrap; gap: 6px; }
.mchip-add { margin-top: 6px; max-width: 320px; }
.grid3 .span2 { grid-column: span 2; }
.grid3 .span3, .grid2 .span2 { grid-column: 1 / -1; }
.modal .grid3 label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 14px; }
.info-grid.one { grid-template-columns: 1fr; }
table.compact td, table.compact th { padding: 6px 10px; }
.hint.danger { color: #991b1b; }

.doc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 8px; }
.doc-col { background: #fafbfc; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px 4px; min-width: 0; }
.col-title { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--primary-dark); margin: 6px 0 12px; display: flex; align-items: center; gap: 10px; }
.sub-box { border: 1px solid var(--border); border-radius: 10px; padding: 4px 16px 10px; margin: 12px 0; }
.cust-info { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; margin-bottom: 12px; }
.tax-box { width: 100%; background: var(--primary-soft); border-radius: 6px; padding: 6px 10px; }
.doc-bottom { display: grid; grid-template-columns: 1fr minmax(320px, 420px); gap: 16px; align-items: start; margin-top: 12px; }

table.doc-lines td { vertical-align: top; }
table.doc-lines td.pname { min-width: 220px; }
input.num.s { width: 64px; }
input.w-note { width: 100%; max-width: 260px; padding: 4px 8px; margin-top: 6px; font-size: 12px; }
table.doc-lines input.num.w { width: 110px; }
input.w-lot { width: 90px; padding: 5px 8px; }
select.dsel { height: 30px; padding: 2px 4px; margin-left: 4px; }
tr.lot-row td { background: #f8f5ff; }
tr.lot-split td { background: #faf8ff; border-top: 1px dashed #e4dcf7; }
select.lot-sel { min-width: 140px; height: 32px; }
select.lot-sel.need, input.w-lot.need { border-color: #f3b4b2; background: #fff8f8; }
.lot-editor { padding: 4px 0; }
.lot-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 8px 0; }
.lot-cell { display: flex !important; flex-direction: column; gap: 4px; font-size: 12px; margin: 0 !important; }
.noimg { display: inline-block; width: 40px; height: 40px; border-radius: 6px; background: #f1f2f4; border: 1px dashed #d1d5db; }
img.cover, .noimg.cover { width: 110px; height: 110px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); }
.prod-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.prod-head h3 { margin: 4px 0; font-size: 18px; }
.prod-head > div:nth-child(2) { flex: 1; }
.price-line { margin-top: 6px; }
.barcode svg { width: 200px; height: auto; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.list-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 13px; }
.cost-row { display: flex; gap: 8px; margin-bottom: 8px; }
.cost-row input:first-child { flex: 1; }
ul.sug { margin: 6px 0 0; padding-left: 18px; }
ul.sug li { margin: 4px 0; }
.steps small { line-height: 1.3; }
@media (max-width: 960px) { .doc-cols, .doc-bottom { grid-template-columns: 1fr; } }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1f2937; color: #fff; padding: 11px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; animation: slide .2s ease; }
.toast.error { background: var(--danger); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

#print-area { display: none; }

/* ---------- Responsive ---------- */
.backdrop { display: none; }
@media (max-width: 960px) {
  .grid-2col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
  .menu-btn { display: block; }
  .topbar { padding: 0 16px; }
  .view { padding: 16px; }
  input.search { min-width: 0; flex: 1 1 100%; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .top-date { display: none; }
  .modal-wrap { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}

/* ---------- Print (hóa đơn) ---------- */
@media print {
  body { background: #fff; }
  .app, .modal-wrap, #toasts { display: none !important; }
  #print-area { display: block; }
  .invoice { font-size: 13px; max-width: 720px; margin: 0 auto; }
  .invoice h2, .invoice h3, .invoice .center { text-align: center; }
  .invoice h3 { margin: 16px 0 6px; }
  .invoice table { margin: 12px 0; }
  .invoice th, .invoice td { border: 1px solid #999; padding: 6px 8px; background: none; }
  .invoice .sign { display: flex; justify-content: space-around; margin-top: 30px; text-align: center; }
  .labels { display: flex; flex-wrap: wrap; gap: 6mm; }
  .label { width: 62mm; border: 1px dashed #999; padding: 3mm; font-size: 10pt; text-align: center; break-inside: avoid; }
  .label svg { width: 100%; height: auto; }
}

/* Thao tác hàng loạt sản phẩm */
.bulk-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin-bottom: 8px; border-radius: 8px; background: var(--bg, #f6f7f9); color: #667; font-size: 13px; }
.bulk-bar.on { background: #e8f1ff; color: #1a4fa0; }
.bulk-bar select { min-width: 220px; }
tr.picked td { background: #f0f6ff; }
tr.inactive td { opacity: .6; }
tr.inactive td:first-child { opacity: 1; }
.strike { text-decoration: line-through; }

/* ---------- Hộp chọn mẫu in ---------- */
.print-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 55; }
.print-modal { max-width: 680px; }
.print-docs { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-bottom: 18px; }
.modal label.radio { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin: 0; font-size: 14px; }
.modal label.radio input { width: 18px; height: 18px; accent-color: var(--primary); }
.paper-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 10px 0 20px; }
.paper-btns .btn { justify-content: center; padding: 10px; }
@media (max-width: 600px) { .paper-btns { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Trang in theo khổ giấy ---------- */
@media print {
  .sheet { color: #000; font-size: 12px; }
  .paper-A4 .sheet { max-width: 186mm; margin: 0 auto; font-size: 12.5px; }
  .paper-A5 .sheet { max-width: 132mm; margin: 0 auto; font-size: 10.5px; }
  .paper-A5 .sheet th, .paper-A5 .sheet td { padding: 3px 4px; }
  .sheet .ps-head h2 { font-size: 1.35em; margin: 0; }
  .sheet .ps-head, .sheet h3, .sheet .center { text-align: center; }
  .sheet h3 { font-size: 1.4em; margin: 12px 0 4px; }
  .sheet .ps-infos { margin: 10px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }
  .sheet .ps-info span { color: #444; }
  .sheet table { width: 100%; border-collapse: collapse; margin: 8px 0; }
  .sheet th, .sheet td { border: 1px solid #888; padding: 5px 6px; background: none; text-align: left; vertical-align: top; }
  .sheet th.r, .sheet td.r { text-align: right; }
  .sheet td.c { text-align: center; }
  .sheet .ps-sums { margin-left: auto; width: 60%; }
  .sheet .ps-sum { display: flex; justify-content: space-between; padding: 2px 0; }
  .sheet .ps-sum.b { font-weight: 700; }
  .sheet .sign { display: flex; justify-content: space-around; margin-top: 24px; text-align: center; min-height: 90px; }
  /* Máy in nhiệt K80 / K57 */
  .paper-K80 .sheet { width: 72mm; font-size: 11px; }
  .paper-K57 .sheet { width: 48mm; font-size: 9.5px; }
  .sheet.thermal .ps-head h2 { font-size: 1.25em; }
  .sheet.thermal h3 { font-size: 1.15em; margin: 6px 0 2px; }
  .sheet.thermal .ps-infos { display: block; border-bottom: 1px dashed #000; padding-bottom: 4px; }
  .sheet.thermal .ps-line { border-bottom: 1px dashed #999; padding: 3px 0; }
  .sheet.thermal .ps-row { display: flex; justify-content: space-between; gap: 6px; }
  .sheet.thermal .ps-small { font-size: .9em; color: #333; }
  .sheet.thermal .ps-sums { width: 100%; border-top: 1px solid #000; margin-top: 4px; padding-top: 2px; }
  .sheet.thermal .ps-thanks { margin-top: 8px; font-style: italic; }
}

/* ---------- Phân quyền ---------- */
.perm-head .row-btns { align-items: center; }
.perm-head label.inline { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 0; }
.perm-head label.inline select { min-width: 280px; }
label.big-check { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; padding: 10px 14px; border: 1px dashed var(--border); border-radius: 8px; }
.perm-table td.c, .perm-table th { text-align: center; }
.perm-table th:first-child, .perm-table td:first-child { text-align: left; }
.perm-table .c-head { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; }
.perm-table tr.perm-mod td { background: #f8fafc; }
.perm-table tr.perm-tab td:first-child { padding-left: 28px; color: #4b5563; }
.perm-table tr.off td { opacity: .45; }
.perm-table input[type=checkbox] { width: 17px; height: 17px; }
.perm-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 10px; }
.perm-sec { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.perm-sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px; background: #f1f5f9; }
.perm-field { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 12px; border-top: 1px solid #f1f5f9; font-size: 13px; }
.perm-field.view span { color: #b45309; }
.perm-field.hide span { color: #9ca3af; text-decoration: line-through; }
select.sm { padding: 3px 6px; font-size: 12.5px; height: auto; }
.field.ro .ro-val { padding: 8px 10px; background: #f8fafc; border: 1px dashed var(--border); border-radius: 6px; min-height: 36px; }

.cost-row input.w-date { width: 150px; flex: none; }

.cost-row { flex-wrap: wrap; align-items: center; }
.cost-row input:first-child { min-width: 180px; }
.cost-row .num.w { width: 130px; }


/* ---------- Bảng dùng chung (grid.js) ---------- */
.g-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: #667; position: relative; }
.g-bar.on { background: #e8f1ff; color: #1a4fa0; }
.g-bar .g-act { min-width: 200px; padding: 4px 8px; }
.g-count { color: #888; }
th.g-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.g-sort:hover { color: var(--primary); }
th.g-sort.asc::after { content: ' ▲'; font-size: 10px; color: var(--primary); }
th.g-sort.desc::after { content: ' ▼'; font-size: 10px; color: var(--primary); }
tr.g-filter td, tr.g-filter th { padding: 4px 6px !important; background: #fafbfc; }
input.g-f { width: 100%; min-width: 60px; padding: 3px 6px; font-size: 12px; border: 1px solid #e3e6ea; border-radius: 4px; font-weight: 400; }
.g-ctl { width: 30px; text-align: center !important; }
.qv-btn { border: 0; background: #eef2f7; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1; transition: transform .15s; }
.qv-btn.open { transform: rotate(90deg); background: var(--primary); color: #fff; }
tr.qv-row > td { background: #f6f9fd !important; padding: 12px 16px !important; }
.qv .info-grid { margin-bottom: 10px; }
.qv-total { text-align: right; margin: 8px 0; }
.g-pop { position: absolute; right: 12px; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 12px 14px; max-height: 60vh; overflow: auto; min-width: 240px; display: flex; flex-direction: column; gap: 6px; }
.g-pop label.check { margin: 0; font-weight: 400; }
ol.steps-list { padding-left: 20px; line-height: 1.7; }

/* Mẫu in & cấu hình */
.paper-btns .btn { flex-direction: column; gap: 2px; }
.paper-btns .btn small { font-weight: 400; opacity: .75; font-size: 11px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tpl-card label { margin-bottom: 10px; }
.tpl-add { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 200px; border: 2px dashed var(--border); background: transparent; }
a.small { font-size: 12px; display: inline-block; margin-top: 6px; }

/* Sản phẩm: ảnh lớn, tìm theo ảnh, bộ lọc nâng cao */
.pimg { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; display: block; background: #f1f3f5; }
span.pimg.noimg { display: block; }
.sim { font-size: 11px; color: var(--primary); font-weight: 600; text-align: center; margin-top: 3px; }
.img-q { display: flex; align-items: center; gap: 10px; }
.img-q img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.img-drop { border: 2px dashed var(--border); border-radius: 10px; padding: 40px; text-align: center; color: #667; cursor: pointer; font-size: 15px; }
.img-drop:focus { border-color: var(--primary); outline: none; background: #f5f9ff; }
.picker.static { display: block; position: static; margin-bottom: 12px; max-height: none; }
.add-img small { display: block; font-size: 10px; opacity: .7; }
.img-grid:focus { outline: 2px solid #cfe0ff; border-radius: 8px; }
.thumb[draggable="true"] { cursor: grab; }
.cat-btn { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbl-items { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.lbl-items label.check { margin: 0; }
.labels.preview .label { border: 1px dashed #999; padding: 3mm; font-size: 10pt; text-align: center; background: #fff; }
.labels.preview .label svg { width: 100%; height: auto; }
.sup-pick .mchips { margin-bottom: 6px; }
.sup-pick .chip a { color: inherit; text-decoration: none; }
.sup-search { flex: 1; min-width: 220px; }

/* Báo giá / đơn hàng */
.qstats { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0 12px; }
.qstat { border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 8px 14px; cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; min-width: 110px; }
.qstat b { font-size: 20px; }
.qstat span { font-size: 12px; color: #667; }
.qstat.on { border-color: var(--primary); background: #eef5ff; }
a.plink { color: inherit; text-decoration: none; }
a.plink:hover b { color: var(--primary); text-decoration: underline; }
.price-warn { font-size: 11px; max-width: 160px; white-space: normal; text-align: right; }
textarea.w-note { width: 100%; resize: vertical; min-height: 30px; font: inherit; font-size: 13px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; margin-top: 6px; }

/* ---------- Trình soạn mẫu in ---------- */
.tpl-head h2 { margin: 6px 0 14px; font-size: 24px; }
.tpl-head a { color: #667; text-decoration: none; }
.tpl-opts { background: #fff; padding: 14px; border-radius: 10px; margin-bottom: 14px; }
.tpl-edit-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .tpl-edit-wrap { grid-template-columns: 1fr; } }
.tpl-editor { padding: 0; overflow: hidden; }
.te-bar { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; padding: 8px; border-bottom: 1px solid var(--border); background: #fafbfc; position: relative; }
.te-btn { min-width: 30px; height: 30px; border: 1px solid transparent; background: none; border-radius: 4px; cursor: pointer; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; position: relative; padding: 0 6px; }
.te-btn:hover, .te-btn.active { border-color: var(--border); background: #fff; }
.te-btn.wide { font-size: 13px; }
.te-btn input[type=color] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.te-btn.hl { background: #ffef9f; }
.te-sel { height: 30px; padding: 0 6px; font-size: 13px; max-width: 120px; }
.te-area { min-height: 600px; max-height: 75vh; overflow: auto; padding: 16px; outline: none; background: #fff; font-family: 'Times New Roman', serif; font-size: 13px; }
.te-src { width: 100%; min-height: 600px; font-family: Consolas, monospace; font-size: 12px; border: 0; padding: 12px; }
.tpl-preview-box { padding: 14px; position: sticky; top: 10px; }
.tpl-preview-box h3 { margin: 0; color: #888; font-size: 22px; }
#te-preview { max-height: 75vh; overflow: auto; background: #eef0f3; padding: 10px; border-radius: 6px; }
.tpl-scale { zoom: var(--s); }
.tpl-paper { background: #fff; margin: 0 auto; padding: 12mm; box-shadow: 0 2px 10px rgba(0,0,0,.12); font-family: 'Times New Roman', serif; font-size: 13px; color: #000; }
.tpl-paper.paper-A4 { width: 210mm; min-height: 297mm; }
.tpl-paper.paper-A5 { width: 148mm; min-height: 210mm; padding: 8mm; }
.tpl-paper.paper-K80 { width: 80mm; padding: 3mm; font-size: 11px; }
.tpl-paper.paper-K57 { width: 57mm; padding: 2mm; font-size: 10px; }
.tpl-thumb { height: 230px; overflow: hidden; border: 1px solid var(--border); border-radius: 6px; margin: 8px 0; background: #eef0f3; padding: 6px; }
.tpl-doc table { border-collapse: collapse; }
.tpl-doc img { max-width: 100%; }
.tpl-doc p { margin: 4px 0; }
.tpl-actions { margin-top: 14px; }
.kw-pop { right: 8px; left: auto; top: 100%; width: 360px; max-height: 60vh; }
.kw-search { width: 100%; padding: 6px 8px; margin-bottom: 6px; }
.kw-group { font-weight: 700; font-size: 12px; color: var(--primary); margin-top: 8px; text-transform: uppercase; }
.kw-item { border: 0; background: none; text-align: left; padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.kw-item:hover { background: #eef5ff; }
.kw-item code { color: #c0392b; font-size: 12px; }
.store-logo { height: 56px; border-radius: 6px; border: 1px solid var(--border); }
@media print { .tpl-doc { font-family: 'Times New Roman', serif; font-size: 12px; color: #000; } .tpl-doc table { border-collapse: collapse; } }

.ledger-filter { flex-wrap: wrap; gap: 8px; }
.ledger-sum { display: flex; flex-wrap: wrap; gap: 6px 22px; align-items: center; padding: 8px 12px; background: #f6f9fd; border-radius: 8px; margin-bottom: 8px; font-size: 13px; }


/* ---------- Ô tiền, bong bóng xem nhanh, quét mã vạch, phiếu thu chi ---------- */
.qv-bubble { position: fixed; z-index: 70; width: min(640px, 94vw); max-height: 70vh; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 16px 40px rgba(0,0,0,.22); padding: 14px; }
.qv-bubble .qv-x { position: absolute; right: 8px; top: 6px; }
a.qv-link { cursor: pointer; text-decoration: underline dotted; }
.scan-box { max-width: 520px; }
#scan-video { width: 100%; border-radius: 8px; background: #000; max-height: 60vh; }
.pay-wrap { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; align-items: start; }
.pay-wrap .card { margin-bottom: 12px; }
@media (max-width: 900px) { .pay-wrap { grid-template-columns: 1fr; } }

/* ---------- Báo cáo ---------- */
/* Báo cáo: thanh nhóm (Bán hàng / Kho / Tài chính) + bộ lọc – cùng kiểu tab & toolbar với các trang khác */
.rp-top { margin-bottom: 12px; }
.rp-head h2 { margin: 6px 0 2px; }
.rp-head a { text-decoration: none; color: #667; }
.rp-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 14px; }
.rp-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.rp-card { display: flex; gap: 14px; align-items: center; padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: inherit; }
.rp-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(22,119,255,.12); }
.rp-card b { display: block; font-size: 16px; }
.rp-card small { color: #667; }
.rp-ico { width: 52px; height: 52px; border-radius: 50%; background: #e6f0ff; display: flex; align-items: center; justify-content: center; font-size: 24px; flex: none; }
table.pnl { width: 100%; }
table.pnl td { padding: 7px 10px; border-bottom: 1px solid #f0f0f0; }
table.pnl tr.b td { font-weight: 700; background: #f8fafc; }
td.small { font-size: 12px; }

/* Hồ sơ thanh toán: thanh tiến độ các bước */
.ds-steps { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0 10px; }
.ds-step { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 14px; background: #eef1f6; color: #667; font-size: 12px; }
.ds-step b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #d5dbe6; color: #fff; font-size: 11px; }
.ds-step.done { background: #e3f5ea; color: #1d7a45; } .ds-step.done b { background: #2e9e5b; }
.ds-step.cur { background: #e3ecff; color: #1a4fd6; font-weight: 600; } .ds-step.cur b { background: #1a4fd6; }
/* Số liệu tồn kho bấm được → bong bóng danh sách chứng từ */
.stock-link { color: inherit; text-decoration: underline dotted; cursor: pointer; }
.stat .value .stock-link { text-decoration-thickness: 2px; }

/* Mã QR mã đơn trên phiếu in tự động */
.sheet .ps-qr { float: right; text-align: center; margin: 0 0 4px 8px; font-size: 10px; line-height: 1.2; }
.sheet .ps-qr img { display: block; }
.sheet.thermal .ps-qr { float: none; margin: 0 auto 4px; width: fit-content; }
/* Gán ảnh phiếu giao hàng theo QR */
.tk-row { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid #eee; }
.tk-row img { width: 70px; height: 90px; object-fit: cover; border: 1px solid #ddd; border-radius: 4px; cursor: zoom-in; }
.tk-row .tk-info { flex: 1; min-width: 0; }
.tabs-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tabs-row .tabs { flex: 1 1 auto; margin-bottom: 0; }
/* Bộ sưu tập sản phẩm */
.coll-link { font-size: 12px; color: #7a3fc4; text-decoration: none; white-space: nowrap; }
.coll-link:hover { text-decoration: underline; }
.coll-grid { display: grid; grid-template-columns: 1fr; gap: 6px; max-height: 50vh; overflow: auto; margin: 6px 0; }
.coll-item { display: flex; gap: 10px; align-items: center; padding: 6px; border: 1px solid #eee; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.coll-item:hover { background: #f5f7fc; }
.tk-row { flex-wrap: wrap; }
.tk-row select { flex: 1 1 220px; max-width: 100%; min-width: 0; }
.tabs-row .tabs { flex: 0 1 auto; }
/* Nút cài ứng dụng (PWA) & vùng an toàn khi chạy toàn màn hình trên điện thoại */
.install-btn { white-space: nowrap; }
@media (max-width: 640px) { .install-btn { padding: 4px 8px; font-size: 12px; } }
@media (display-mode: standalone) { .topbar { padding-top: max(10px, env(safe-area-inset-top)); } body { padding-bottom: env(safe-area-inset-bottom); } }
/* Trạng thái đồng bộ trên thanh trên */
.sync-pill { border: 1px solid #cfd8ea; background: #f2f6ff; color: #1a4fd6; border-radius: 14px; padding: 3px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.sync-pill.syncing { color: #8a6d00; background: #fff8e1; border-color: #f0dc9a; }
.sync-pill.error, .sync-pill.paused { color: #b42318; background: #fff1f0; border-color: #f5c2bd; }
.sync-pill.offline { color: #666; background: #f3f3f3; border-color: #ddd; }
@media (max-width: 640px) { .sync-pill { padding: 3px 6px; font-size: 11px; } }

/* Dòng đơn hoàn trong bảng tính hoa hồng */
.ret-row td { background: #fff6f5; }

/* Trường kiểu tệp đính kèm */
.file-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.file-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-link { text-decoration: none; color: #1a4fd6; word-break: break-all; }
.file-link:hover { text-decoration: underline; }

/* Nhân viên bị "Ẩn mọi giá tiền": ẩn các ô nhập tiền trong phần tổng của form chứng từ */
body.no-price #modal:not(.price-open) .summary .sum-row:has(input, select) { display: none; }
.amt-pct { display: inline-flex; gap: 4px; align-items: center; }
.amt-pct input { width: 120px; }
.amt-pct select { width: 56px; padding-left: 6px; padding-right: 4px; }
.hbar { height: 8px; background: #eef0f3; border-radius: 4px; overflow: hidden; min-width: 60px; }
.hbar > i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

/* ---------- Tối ưu điện thoại / ứng dụng cài đặt ---------- */
/* Không phần tử nào được làm trang rộng hơn màn hình (tránh trình duyệt điện thoại thu nhỏ cả trang) */
.main { overflow-x: clip; }
.topbar h1 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal { min-width: 0; }
.modal-body > *, .doc-cols > *, .doc-bottom > *, .grid2 > *, .grid3 > * { min-width: 0; }
.modal input, .modal select, .modal textarea { max-width: 100%; }
.sug-more { display: none; margin-top: 2px; }
@media (max-width: 860px) {
  /* thanh trên: tiêu đề co lại, nút cài chỉ còn biểu tượng, ô người dùng gọn */
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar h1 { flex: 1 1 auto; font-size: 16px; }
  .topbar .spacer { display: none; }
  .hide-sm { display: none; }
  .install-btn { padding: 0 8px; }
  .user-pick { margin-left: 0; }
  .user-pick > span { display: none; }
  .user-pick select { max-width: 112px; height: 32px; padding: 4px 6px; }
  /* chữ ô nhập 16px: iPhone không tự phóng to khi chạm vào ô */
  input, select, textarea { font-size: 16px; }
  input.g-f, select.sm, .te-sel { font-size: 13px; }
  /* nút đủ lớn để bấm bằng ngón tay */
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  .icon-btn { padding: 8px 10px; }
  .toolbar > * { flex: 1 1 auto; }
  .toolbar input.search { flex-basis: 100%; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat .value { font-size: 18px; word-break: break-word; }
  .card.pad { padding: 14px; }
  .card-head { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .tab { padding: 10px 12px; }
  /* cảnh báo dài chỉ hiện 3 dòng đầu */
  ul.sug.fold > li:nth-child(n+4) { display: none; }
  .sug-more { display: inline-block; }
  /* hộp thoại toàn màn hình: tiêu đề ghim trên, nút Lưu ghim dưới – không phải cuộn hết form mới thấy nút */
  .modal { display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; z-index: 3; background: #fff; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .modal-head h2 { font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .modal-body { padding: 14px; flex: 1; }
  .modal-foot { position: sticky; bottom: 0; z-index: 3; background: #fff; padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom)); box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
  .modal-foot .btn { flex: 1 1 auto; }
  .doc-col { padding: 12px 12px 2px; }
  .doc-bottom { grid-template-columns: 1fr; }
  .totals { max-width: none; }
  .qv-bubble { left: 8px !important; right: 8px; width: auto; max-height: 75vh; }
  #toasts { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); align-items: center; }
  .toast { max-width: 100%; }
}
