: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; }

