/* QuầyPOS — giao diện quản lý bán hàng */
:root {
  --primary: #1463d6;
  --primary-600: #0f52b5;
  --primary-50: #eaf2ff;
  --green: #13a356;
  --green-600: #0e8a48;
  --red: #d93636;
  --red-50: #fdeeee;
  --orange: #d97a06;
  --orange-50: #fff4e5;
  --text: #1d2433;
  --text-2: #4a5468;
  --muted: #7b8497;
  --border: #e2e6ee;
  --bg: #f2f4f8;
  --surface: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --header-h: 52px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-green { color: var(--green); }
.text-primary { color: var(--primary); }
.bold { font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.span-3 { grid-column: 1 / -1; }
.span-2 { grid-column: span 2; }

/* ---------- Header / navigation ---------- */
.app-header {
  height: var(--header-h); background: var(--primary); color: #fff;
  display: flex; align-items: center; padding: 0 16px; gap: 4px;
  position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin-right: 18px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 32px; max-width: 120px; padding: 2px; border-radius: 7px; background: #fff; display: flex; align-items: center; }
.brand-logo img { max-height: 28px; max-width: 116px; object-fit: contain; display: block; }
/* Logo có nền màu: không khung trắng, ảnh tràn khung và bo góc */
.brand-logo.plain { padding: 0; background: transparent; overflow: hidden; }
.brand-logo.plain img { max-height: 32px; max-width: 120px; border-radius: 7px; }
.login-card .brand-logo.plain img { max-height: 56px; max-width: 200px; border-radius: 10px; }
.login-card .brand-logo { height: 56px; max-width: 200px; }
.login-card .brand-logo img { max-height: 52px; max-width: 196px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: #fff; color: var(--primary); display: grid; place-items: center; font-size: 15px; font-weight: 800; }
.nav { display: flex; gap: 2px; height: 100%; }
.nav-item { position: relative; display: flex; align-items: center; }
.nav-link {
  color: #fff; padding: 0 12px; height: 100%; display: flex; align-items: center; gap: 6px;
  border: 0; background: none; cursor: pointer; opacity: .92; font-weight: 500; white-space: nowrap;
}
.nav-link:hover, .nav-item:hover > .nav-link { background: rgba(255,255,255,.12); opacity: 1; text-decoration: none; }
.nav-link.active { background: var(--primary-600); opacity: 1; }
.nav-link svg { width: 16px; height: 16px; }
.dropdown {
  display: none; position: absolute; top: 100%; left: 0; min-width: 200px; background: #fff; color: var(--text);
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-lg); padding: 6px 0; z-index: 60;
}
.nav-item:hover .dropdown, .nav-item:focus-within .dropdown { display: block; }
.dropdown a { display: block; padding: 8px 16px; color: var(--text); }
.dropdown a:hover { background: var(--primary-50); text-decoration: none; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn-pos {
  background: var(--green); color: #fff; border: 0; height: 36px; padding: 0 16px; border-radius: 6px;
  font-weight: 600; display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.btn-pos:hover { background: var(--green-600); text-decoration: none; }
.bell { position: relative; width: 36px; height: 36px; border-radius: 6px; display: grid; place-items: center; color: #fff; background: rgba(255,255,255,.12); }
.bell:hover { background: rgba(255,255,255,.22); text-decoration: none; }
.bell-count { position: absolute; top: -4px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--primary, #0b63c5); }
.bell-count.warn { background: var(--orange); }
.lot-chip { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; color: var(--text-2); }
.user-menu { position: relative; }
.user-btn { background: rgba(255,255,255,.12); border: 0; color: #fff; height: 36px; padding: 0 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: #fff; color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-menu .dropdown { right: 0; left: auto; border-radius: var(--radius); margin-top: 6px; }
.user-menu:focus-within .dropdown { display: block; }
.menu-toggle { display: none; }

/* ---------- Layout ---------- */
.page { padding: 16px 20px 40px; max-width: 1480px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.layout-side { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.layout-side > *, .dash-grid > *, .editor > * { min-width: 0; }
.side-panel { display: flex; flex-direction: column; gap: 12px; position: sticky; top: calc(var(--header-h) + 16px); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 14px 16px; }
.card-head { flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.filter-box { padding: 12px 14px; }
.filter-box h3 { font-size: 13px; margin-bottom: 8px; }
.filter-box label.opt { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; color: var(--text-2); }

/* ---------- Form controls ---------- */
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20,99,214,.15); }
.input.num { text-align: right; }
.input.invalid { border-color: var(--red); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field .err { color: var(--red); font-size: 12px; }
.search { position: relative; }
.search .input { padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }

.btn {
  height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: #f6f8fb; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-600); }
.btn-danger { color: var(--red); border-color: #f2c4c4; }
.btn-danger:hover { background: var(--red-50); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; }
.btn-ghost { border-color: transparent; background: transparent; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { background: #eef3fb; font-weight: 600; font-size: 13px; color: var(--text-2); position: sticky; top: 0; white-space: nowrap; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f6f9ff; }
.table tbody tr.open { background: var(--primary-50); }
.table tr.summary td { background: #fbfcfe; font-weight: 600; }
.table tr.detail > td { background: #fbfcff; padding: 0; border-bottom: 2px solid var(--primary); }
.table .empty { text-align: center; color: var(--muted); padding: 40px; }
.detail-box { padding: 16px; }
.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.detail-tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; }
.detail-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 24px; margin-bottom: 12px; }
.info-grid div { display: flex; gap: 8px; border-bottom: 1px dashed var(--border); padding: 4px 0; }
.info-grid div > span:first-child { color: var(--muted); min-width: 110px; }

.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; background: #eef0f4; color: var(--text-2); white-space: nowrap; }
.badge.green { background: #e5f6ec; color: var(--green-600); }
.badge.red { background: var(--red-50); color: var(--red); }
.badge.orange { background: var(--orange-50); color: var(--orange); }
.badge.blue { background: var(--primary-50); color: var(--primary); }

.pager { display: flex; align-items: center; gap: 6px; padding: 10px 12px; color: var(--text-2); flex-wrap: wrap;
  position: sticky; bottom: 0; z-index: 5; background: var(--surface, #fff); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); }
.pager .btn-sm { min-width: 32px; justify-content: center; }
.pager .btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-gap { padding: 0 2px; color: var(--text-3, #94a3b8); }
.pager-size select { border: 1px solid var(--border); border-radius: 6px; padding: 3px 4px; background: transparent; color: inherit; font: inherit; }
.pager-go { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; }
.pager-go .input { width: 70px; height: 30px; padding: 0 8px; }
.pager .spacer { flex: 1; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.kpi-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-label { color: var(--text-2); font-size: 13px; }
.kpi-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.kpi-delta { font-size: 12px; }
.dash-grid { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
.chart { position: relative; height: 280px; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover, .chart .bar.hl { fill: var(--primary-600); }
.chart .grid line { stroke: #edf0f5; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.tooltip { position: absolute; pointer-events: none; background: #1d2433; color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px; z-index: 5; }
.seg { display: inline-flex; background: #eef0f4; border-radius: 6px; padding: 2px; }
.seg button { white-space: nowrap; border: 0; background: none; padding: 4px 10px; border-radius: 5px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); font-weight: 500; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.list li:last-child { border-bottom: 0; }
.rank { width: 22px; height: 22px; border-radius: 50%; background: #eef0f4; display: grid; place-items: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.bar-inline { height: 6px; border-radius: 3px; background: var(--primary); margin-top: 4px; }

/* ---------- Modal / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 6vh 16px; overflow-y: auto; animation: fade .12s; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); animation: pop .15s; }
.modal.lg { max-width: 920px; }
.modal.sm { max-width: 420px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: #fafbfc; border-radius: 0 0 10px 10px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.toasts { position: fixed; right: 16px; top: 64px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 240px; max-width: 420px; animation: pop .15s; border-left: 4px solid var(--green); }
.toast.error { border-left-color: var(--red); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f52b5 0%, #1463d6 50%, #3b82f6 100%); padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: var(--shadow-lg); }
.login-card .brand { color: var(--primary); justify-content: center; margin: 0 0 6px; font-size: 22px; }
.login-card .brand-mark { background: var(--primary); color: #fff; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-card .btn { height: 42px; }
.login-hint { margin-top: 14px; padding: 10px; background: var(--primary-50); border-radius: 8px; font-size: 12.5px; color: var(--text-2); }

/* ---------- Line editor (phiếu nhập / kiểm kho) ---------- */
.editor { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.ac { position: relative; }
.ac-list { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow-lg); max-height: 340px; overflow-y: auto; z-index: 30; margin-top: 4px; color: var(--text); text-align: left; }
.ac-item { padding: 8px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #f1f3f7; }
.ac-item:last-child { border-bottom: 0; }
.ac-item.active, .ac-item:hover { background: var(--primary-50); }
.ac-item .ac-main { flex: 1; min-width: 0; }
.ac-item .ac-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qty-input { width: 80px; height: 32px; text-align: right; }
.sum-line { display: flex; justify-content: space-between; padding: 6px 0; }
.sum-line.total { font-size: 16px; font-weight: 700; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }

/* ---------- POS ---------- */
body.pos-mode { overflow: hidden; }
.pos { display: grid; grid-template-rows: 52px auto 1fr; height: 100vh; }
.pos-top { background: var(--primary); display: flex; align-items: center; gap: 10px; padding: 0 12px; color: #fff; }
.pos-top .search { width: 420px; max-width: 40vw; }
.pos-top .search .input { border: 0; height: 38px; }
.pos-tabs { display: flex; gap: 4px; align-items: flex-end; height: 100%; overflow-x: auto; }
.pos-tab { height: 38px; margin-top: 14px; padding: 0 10px 0 14px; background: rgba(255,255,255,.15); color: #fff; border-radius: 8px 8px 0 0; display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; border: 0; }
.pos-tab.active { background: var(--bg); color: var(--text); font-weight: 600; }
.pos-tab .x { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; opacity: .7; font-size: 15px; line-height: 1; }
.pos-tab .x:hover { background: rgba(0,0,0,.12); opacity: 1; }
.pos-tab-add { background: rgba(255,255,255,.15); border: 0; color: #fff; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 20px; margin-bottom: 3px; }
.pos-top .icon-btn { background: rgba(255,255,255,.12); color: #fff; border: 0; height: 36px; padding: 0 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.pos-top .icon-btn:hover { background: rgba(255,255,255,.22); text-decoration: none; }
.pos-top .icon-btn.warn { background: var(--orange); }
.shift-close { align-items: start; }
.denoms td { padding-top: 4px; padding-bottom: 4px; }
.denoms .qty-input { width: 70px; }
.appr-btn { position: relative; }
.appr-lines td, .appr-lines th { font-size: 13px; }
.appr-log { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.appr-log li { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.pos-body { display: grid; grid-template-columns: 1fr 400px; gap: 10px; padding: 10px; min-height: 0; }
.pos-body > * { min-width: 0; }
.pos-left { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.cart { flex: 1; overflow-y: auto; min-height: 0; }
.cart-empty { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 40px; }
.cart-empty svg { width: 56px; height: 56px; opacity: .4; margin-bottom: 8px; }
.cart-line { display: grid; grid-template-columns: 28px 28px 1fr 120px 110px 120px; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.cart-line:hover { background: #fafcff; }
.cart-line.gift-line { background: #f3fbf5; }
.promo-tag { font-size: 12px; color: var(--green); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.promo-applied { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
.promo-applied .chip { font-size: 12px; background: #eaf7ee; color: var(--green); border-color: transparent; cursor: default; }
.cart-line .del { border: 0; background: none; cursor: pointer; color: var(--muted); width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; }
.cart-line .del:hover { color: var(--red); background: var(--red-50); }
.cart-line .name { font-weight: 500; }
.stepper { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; height: 32px; }
.stepper button { width: 30px; height: 100%; border: 0; background: #f6f8fb; cursor: pointer; font-size: 16px; }
.stepper button:hover { background: #e9eef6; }
.stepper input { width: 100%; min-width: 0; border: 0; text-align: center; height: 100%; outline: none; }
.price-input { border: 0; border-bottom: 1px dashed var(--border); width: 100%; text-align: right; height: 30px; outline: none; background: transparent; }
.price-input:focus { border-bottom-color: var(--primary); }
.quick-grid { height: 240px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding: 10px; align-content: start; }
.quick-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: pointer; background: #fff; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 74px; }
.quick-item:hover { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(20,99,214,.12); }
.quick-item .qn { font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.quick-item .qp { color: var(--primary); font-weight: 600; margin-top: auto; }
.quick-cats { display: flex; gap: 6px; padding: 10px 10px 0; overflow-x: auto; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 4px 12px; cursor: pointer; white-space: nowrap; font-size: 13px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pos-right { display: flex; flex-direction: column; min-height: 0; }
.pos-right .card-body { flex: 1; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.pay-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pay-row .input { width: 150px; text-align: right; }
.pay-total { font-size: 20px; font-weight: 700; color: var(--primary); }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pay-methods button { border: 1px solid var(--border); background: #fff; border-radius: 6px; height: 36px; cursor: pointer; }
.pay-methods button.active { border-color: var(--primary); background: var(--primary-50); color: var(--primary); font-weight: 600; }
.quick-cash { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-cash button { border: 1px solid var(--border); background: #fff; border-radius: 16px; padding: 4px 10px; cursor: pointer; font-size: 13px; }
.quick-cash button:hover { border-color: var(--primary); color: var(--primary); }
.btn-pay { height: 56px; font-size: 17px; font-weight: 700; border-radius: 8px; width: 100%; letter-spacing: .3px; }
.cust-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--primary-50); border-radius: 6px; }
.cust-chip .x { margin-left: auto; cursor: pointer; border: 0; background: none; font-size: 18px; color: var(--muted); }
.kbd { display: inline-block; padding: 0 5px; border: 1px solid rgba(0,0,0,.15); border-bottom-width: 2px; border-radius: 4px; font-size: 11px; line-height: 16px; background: rgba(255,255,255,.7); color: var(--text-2); }
.pos-top .kbd { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.3); }
.qr-box { text-align: center; }
.qr-box img { width: 220px; height: auto; border-radius: 8px; border: 1px solid var(--border); }

/* ---------- In ấn (hóa đơn, tem) ----------
   Khi in chỉ hiện #print-area; khổ giấy (@page) do js/print.js đặt theo từng loại bản in. */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  html, body { background: #fff !important; height: auto; overflow: visible !important; }
}

/* Hóa đơn: các biến --rw (bề rộng), --rfs (cỡ chữ), --rff (font) do mẫu in đặt */
.receipt { width: var(--rw, 72mm); padding: var(--rpad, 2mm 3mm); font-family: var(--rff, Arial, sans-serif); font-size: var(--rfs, 12px);
  line-height: 1.35; color: #000; background: #fff; box-sizing: border-box; word-wrap: break-word; }
.receipt * { box-sizing: border-box; }
.receipt h2 { text-align: center; font-size: 1.25em; margin: 0 0 2px; }
.receipt h3 { text-align: center; font-size: 1.12em; margin: 4px 0 2px; }
.receipt .c { text-align: center; }
.receipt .r { text-align: right; white-space: nowrap; }
.receipt td + td.r, .receipt th + th.r { padding-left: 6px; }
.receipt .b { font-weight: 700; }
.receipt .sm { font-size: .88em; }
.receipt table { width: 100%; border-collapse: collapse; margin: 4px 0; }
.receipt td, .receipt th { padding: 2px 0; vertical-align: top; text-align: left; }
.receipt th { border-bottom: 1px solid #000; font-weight: 700; }
.receipt .line { border-top: 1px dashed #000; margin: 5px 0; }
.receipt .logo { display: block; margin: 0 auto 4px; max-width: 100%; }
.receipt .bc { display: flex; justify-content: center; margin: 6px 0 2px; }
.receipt .qr { display: block; margin: 4px auto; width: 38mm; }
.receipt table.vat { font-size: .88em; margin-top: 2px; }
.receipt table.vat th { font-weight: 600; }
.receipt.a4 table.items td, .receipt.a4 table.items th { padding: 4px 6px; border: 1px solid #000; }

/* Tem mã vạch */
.label-sheet { position: relative; overflow: hidden; background: #fff; break-after: page; page-break-after: always; }
.label-sheet:last-child { break-after: auto; page-break-after: auto; }
.label { position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  overflow: hidden; color: #000; font-family: Arial, sans-serif; line-height: 1.12; padding: 0.6mm 1mm; }
.label .l-store { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.label .l-name { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; max-width: 100%; }
.label .l-code { letter-spacing: .3px; }
.label .l-price { font-weight: 700; }
.label svg.barcode { display: block; margin: .4mm 0 .2mm; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
  .layout-side { grid-template-columns: 1fr; }
  .side-panel { position: static; flex-direction: row; flex-wrap: wrap; }
  .side-panel > * { flex: 1 1 200px; }
  .pos-body { grid-template-columns: 1fr 340px; }
  .cart-line { grid-template-columns: 28px 1fr 110px 100px; }
  .cart-line .idx, .cart-line .lt { display: none; }
  .editor { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .menu-toggle { display: inline-flex; background: none; border: 0; color: #fff; cursor: pointer; padding: 6px; }
  .nav { display: none; position: absolute; top: var(--header-h); left: 0; right: 0; background: var(--primary-600); flex-direction: column; height: auto; padding: 8px 0; }
  .nav.open { display: flex; }
  .nav-link { height: 42px; }
  .nav .dropdown { position: static; box-shadow: none; background: rgba(255,255,255,.06); border-radius: 0; display: block; padding: 0; }
  .nav .dropdown a { color: #fff; padding-left: 32px; }
  .brand { margin-right: 0; }
  .btn-pos { padding: 0 12px; }
  .grid-2, .grid-3, .info-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  body.pos-mode { overflow: auto; }
  .pos { height: auto; min-height: 100vh; grid-template-rows: 52px auto auto; }
  .pos-top { position: sticky; top: 0; z-index: 20; }
  .pos-body { grid-template-columns: 1fr; }
  .cart { max-height: 45vh; min-height: 90px; }
  .cart-line { grid-template-columns: 28px 1fr 100px; }
  .cart-line .price-input { display: none; }
  .quick-grid { height: 200px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .pos-right .card-body { overflow: visible; }
  .pos-top .search { width: auto; max-width: none; flex: 1; min-width: 0; }
  .pos-top > .small, .pos-top > .spacer { display: none; }
  .pay-methods button { font-size: 13px; padding: 0 4px; }
  .pos-tabs { display: none; }
  .page { padding: 12px; }
  .page-head .search { width: 100% !important; order: 3; }
  .kpis { grid-template-columns: 1fr; }
  .side-panel > * { flex: 1 1 100%; }
  .user-btn .uname { display: none; }
}

/* ---------- Chi nhánh ---------- */
.branch-picker { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 4px 0 10px; border-radius: 6px; background: rgba(255,255,255,.14); color: #fff; max-width: 240px; }
.branch-picker svg { width: 17px; height: 17px; flex-shrink: 0; }
.branch-picker select { background: transparent; border: 0; color: #fff; font-weight: 600; height: 100%; outline: none; cursor: pointer; min-width: 0; max-width: 200px; text-overflow: ellipsis; }
.branch-picker select option { color: var(--text); }
.branch-picker.single { padding-right: 12px; font-weight: 600; }
.branch-picker.single span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius); background: var(--orange-50); color: #8a4b00; margin-bottom: 14px; }
.alert-bar svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert-bar a { margin-left: auto; font-weight: 600; }
.return-qty { width: 90px; }
.chk-list { display: grid; gap: 6px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; max-height: 180px; overflow-y: auto; }
.chk-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
@media (max-width: 820px) {
  .app-header .branch-picker { max-width: 120px; padding: 0 2px 0 8px; }
  .app-header .branch-picker select { max-width: 90px; font-size: 13px; }
  .brand span:last-child { display: none; }
}
.hide-sm { margin-left: 2px; }
@media (max-width: 820px) { .hide-sm { display: none; } }
.alert-bar { flex-wrap: wrap; }
.alert-bar a { white-space: nowrap; }
@media (max-width: 820px) {
  .btn-pos { padding: 0 12px; }
  .page-head h1 .muted { display: block; font-size: 15px; }
}

/* ---------- Thiết lập giá ---------- */
.pl-item { display: block; width: 100%; border: 0; background: none; padding: 10px 14px; cursor: pointer; border-left: 3px solid transparent; }
.pl-item:hover { background: #f6f9ff; }
.pl-item.active { background: var(--primary-50); border-left-color: var(--primary); }
.pl-item + .pl-item { border-top: 1px solid var(--border); }

/* ---------- Mẫu in hóa đơn ---------- */
.tpl-layout { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(320px, 520px); gap: 16px; align-items: start; }
.tpl-preview-wrap { background: #e9edf3; border-radius: var(--radius); padding: 20px; display: flex; justify-content: center; overflow: auto; max-height: calc(100vh - 140px); position: sticky; top: calc(var(--header-h) + 16px); }
.tpl-paper { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); transform-origin: top center; }
.tpl-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.tpl-opts label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.token-list { display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; overflow-y: auto; }
.token-list button { border: 1px solid var(--border); background: #fff; border-radius: 4px; padding: 2px 6px; font: 12px/1.4 ui-monospace, Consolas, monospace; cursor: pointer; }
.token-list button:hover { border-color: var(--primary); color: var(--primary); }
textarea.code { font: 12.5px/1.5 ui-monospace, Consolas, "Courier New", monospace; min-height: 360px; white-space: pre; tab-size: 2; }
@media (max-width: 1100px) { .tpl-layout { grid-template-columns: 1fr; } .tpl-preview-wrap { position: static; } }

/* Chọn file nhập dữ liệu */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; align-items: center;
  gap: 8px; cursor: pointer; color: var(--text-2); text-align: center; background: var(--primary-50); }
.dropzone:hover { border-color: var(--primary); color: var(--primary); }
details summary { cursor: pointer; }
.cat-scroll { max-height: 340px; overflow-y: auto; margin-right: -6px; padding-right: 6px; }
.unit-select { border: 1px solid var(--border); border-radius: 4px; font-size: 12px; padding: 1px 4px; background: var(--surface, #fff); color: var(--text); max-width: 190px; }
.units-table td { padding: 4px 6px; vertical-align: middle; }
.units-table input { height: 32px; }
.logo-box { width: 180px; height: 80px; border: 1px dashed var(--border); border-radius: 8px; display: grid; place-items: center; text-align: center; background: #fff; overflow: hidden; }
.logo-box img { max-width: 170px; max-height: 72px; object-fit: contain; }
.clock-btn { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; border-radius: 6px; border: 0; color: #fff;
  background: rgba(255,255,255,.12); cursor: pointer; font-weight: 600; }
.clock-btn:hover { background: rgba(255,255,255,.22); }
.clock-btn.on { background: #16a34a; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 4px 16px; }
.perm-grid label { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; font-size: 13px; }
.perm-grid .def { color: var(--text-2); font-size: 11px; margin-left: 4px; }
.sched td.cell { min-width: 110px; vertical-align: top; cursor: pointer; }
.sched td.cell:hover { background: var(--primary-50); }
.sched .chip { display: block; font-size: 11.5px; padding: 2px 6px; border-radius: 4px; margin: 2px 0; background: var(--primary-50); color: var(--primary); white-space: nowrap; }
.sched .chip.ok { background: #e7f6ec; color: #13803a; }
.sched .chip.late { background: #fff4e5; color: #b45309; }
.sched .chip.miss { background: #fdecec; color: #c0262d; }
.sched th.today, .sched td.today { background: #fffbe6; }
.table tr.row-today td { background: var(--primary-50); }
.header-right > *, .nav-link { white-space: nowrap; }
.header-right > *:not(.branch-picker) { flex-shrink: 0; }
@media (max-width: 1400px) { .nav-link svg { display: none; } .nav-link { padding: 0 9px; } .header-right { gap: 6px; } }
@media (max-width: 1180px) and (min-width: 821px) { .nav-link { padding: 0 7px; font-size: 14px; } .app-header .branch-picker { max-width: 150px; } .header-right .hide-sm { display: none; } }
@media (max-width: 1560px) { .user-btn .uname { display: none; } }
@media (max-width: 1480px) { .clock-btn .hide-sm { display: none; } }
.version-bar { background: #b91c1c; color: #fff; padding: 8px 16px; font-size: 14px; line-height: 1.45; text-align: center; position: relative; z-index: 60; }

/* ---------- Kiểm hàng (máy tính + điện thoại) ---------- */
.count-page { padding-bottom: 90px; max-width: 1100px; }
.count-bar { display: flex; gap: 8px; align-items: center; padding: 10px; position: sticky; top: calc(var(--header-h) + 6px); z-index: 15; }
.count-search { flex: 1; min-width: 0; }
.count-search .input { height: 46px; font-size: 16px; }
.count-cam { height: 46px; }
.count-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0 8px; }
.count-list { padding: 0; overflow: hidden; }
.count-row { display: grid; grid-template-columns: 1fr auto 70px 36px; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.count-row:last-child { border-bottom: 0; }
.count-row.todo { background: #fafbfd; }
.count-row.flash { animation: countflash 1.2s ease-out; }
@keyframes countflash { from { background: #dbeafe; } to { background: transparent; } }
.count-name { min-width: 0; }
.count-name > b { display: block; overflow: hidden; text-overflow: ellipsis; }
.count-page .page-head { flex-wrap: wrap; }
.count-qty { display: flex; align-items: center; gap: 6px; }
.count-qty .btn { width: 40px; height: 40px; font-size: 20px; font-weight: 600; padding: 0; justify-content: center; }
.count-qty .input { width: 84px; height: 40px; text-align: center; font-size: 17px; font-weight: 600; }
.count-qty .input::placeholder { font-size: 12px; font-weight: 400; }
.count-diff { text-align: center; }
.count-foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; gap: 10px; align-items: center; padding: 10px 16px; border-radius: 0;
  box-shadow: 0 -4px 14px rgba(15, 23, 42, .08); margin: 0; }
.count-foot .count-stats { flex: 1; }
.count-foot .btn { height: 44px; padding: 0 18px; }
.seg-sm button { padding: 3px 8px; font-size: 12px; }
.cam-overlay { position: fixed; inset: 0; z-index: 1000; background: #000; display: flex; flex-direction: column; }
.cam-overlay video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.cam-frame { position: absolute; left: 10%; right: 10%; top: 35%; height: 22%; border: 3px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.cam-bar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: #111; color: #fff; font-size: 15px; }
.cam-bar span { flex: 1; }
@media (max-width: 820px) {
  .count-bar { flex-wrap: wrap; top: calc(var(--header-h) + 2px); }
  .count-mode { width: 100%; }
  .count-mode button { flex: 1; }
  .count-row { grid-template-columns: 1fr auto; grid-template-areas: "name del" "qty diff"; row-gap: 8px; }
  .count-name { grid-area: name; }
  .count-del { grid-area: del; }
  .count-qty { grid-area: qty; }
  .count-diff { grid-area: diff; text-align: right; }
  .count-foot { flex-wrap: wrap; padding: 8px 10px; }
  .count-foot .count-stats { flex-basis: 100%; font-size: 13px; }
  .count-foot [data-saved] { display: none; }
  .count-foot .btn { flex: 1; }
  .count-tools .seg { width: 100%; }
  .count-tools .seg button { flex: 1; }
}
.shelf-row { grid-template-columns: 28px 1fr auto; }
.shelf-pick input { width: 20px; height: 20px; }
@media (max-width: 820px) {
  .shelf-row { grid-template-columns: 28px 1fr; grid-template-areas: "pick name" "pick qty"; }
  .shelf-row .shelf-pick { grid-area: pick; align-self: start; padding-top: 2px; }
  .shelf-row .count-name { grid-area: name; }
  .shelf-row .count-qty { grid-area: qty; justify-content: flex-end; }
}
.count-list > .empty { padding: 28px 16px; text-align: center; }

/* ---------- Trợ lý hỏi đáp ---------- */
.ai-fab { position: fixed; right: 20px; bottom: 20px; z-index: 900; width: 54px; height: 54px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 22px rgba(20, 99, 214, .35); }
.ai-fab svg { width: 26px; height: 26px; }
body:has(.count-foot) .ai-fab { bottom: 84px; }
.ai-root.open .ai-fab { display: none; }
.ai-panel { position: fixed; right: 20px; bottom: 20px; z-index: 901; width: 420px; max-width: calc(100vw - 24px); height: min(640px, calc(100vh - 90px));
  background: var(--surface, #fff); border-radius: 16px; box-shadow: 0 18px 50px rgba(15, 23, 42, .25); display: none; flex-direction: column; overflow: hidden; }
.ai-root.open .ai-panel { display: flex; }
.ai-panel header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; background: var(--primary); color: #fff; }
.ai-panel header .small { opacity: .8; flex: 1; }
.ai-panel header .btn { color: #fff; }
.ai-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #f6f8fb; }
.ai-msg { max-width: 92%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.45; }
.ai-msg p { margin: 0 0 6px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.ai-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; width: 92%; }
.ai-kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 6px 0; }
.ai-kpis div { background: #f3f6fb; border-radius: 8px; padding: 6px 8px; }
.ai-kpis span { display: block; font-size: 11px; color: var(--text-2); }
.ai-table { overflow-x: auto; margin: 6px 0; }
.ai-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ai-table th, .ai-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.ai-table th { color: var(--text-2); font-weight: 600; white-space: nowrap; }
.ai-table .num { text-align: right; white-space: nowrap; }
.ai-link { display: inline-block; margin-top: 4px; font-weight: 600; font-size: 13px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.ai-chips button { border: 1px solid #cfe0f7; background: #eef5ff; color: var(--primary); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; }
.ai-sugg { padding: 6px 12px 0; margin: 0; background: #fff; }
.ai-sugg:empty { display: none; }
.ai-panel form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: #fff; }
.ai-panel form .input { flex: 1; height: 42px; font-size: 15px; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: aidot 1s infinite; }
.ai-dots i:nth-child(2) { animation-delay: .15s; } .ai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes aidot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
@media (max-width: 820px) {
  .ai-fab { right: 14px; bottom: 14px; }
  .ai-panel { inset: 0; width: auto; max-width: none; height: auto; border-radius: 0; right: 0; bottom: 0; }
}

/* Báo cáo lãi lỗ */
.pnl .pnl-sub td { font-weight: 700; background: var(--bg-2, #f7f9fc); }
.pnl .pnl-rev td { font-weight: 700; }
.pnl td a { color: inherit; border-bottom: 1px dashed var(--muted); text-decoration: none; }
.pos > .offline-bar { grid-row: 2; }
.pos > .pos-body { grid-row: 3; min-height: 0; }
.offline-bar { background: var(--orange); color: #fff; padding: 4px 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.offline-bar.ok { background: var(--green); }
.offline-bar button { background: rgba(255,255,255,.2); color: #fff; border: 0; border-radius: 4px; padding: 2px 8px; cursor: pointer; }

/* ---- Đợt 5: ảnh chứng từ, xác thực hai lớp ---- */
.photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.photo-thumb { position: relative; width: 84px; height: 84px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; background: #f6f7f9; padding: 0; cursor: pointer; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-x { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6);
  color: #fff; font-size: 15px; line-height: 20px; cursor: pointer; padding: 0; }
.photo-add { width: 84px; height: 84px; border: 1px dashed var(--border); border-radius: 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; cursor: pointer; color: var(--primary); text-align: center; }
.mfa-qr svg { width: 200px; height: 200px; image-rendering: pixelated; }
.mfa-codes { background: #f6f7f9; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 16px; line-height: 1.7;
  columns: 2; user-select: all; }
.table.wide-name td:nth-child(2), .table.wide-name th:nth-child(2) { min-width: 220px; }
.table.wide-name td.num, .table.wide-name th.num { white-space: nowrap; }
