:root {
  --primary: #0070f4;
  --primary-dark: #0058c4;
  --primary-light: #e8f1fe;
  --header: #0070f4;
  --success: #12a150;
  --success-dark: #0d8240;
  --danger: #e5383b;
  --warning: #f59f00;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #dfe3e8;
  --bg: #eef1f5;
  --card: #ffffff;
  --row-hover: #f4f8fe;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
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);
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.bold { font-weight: 600; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.flex { display: flex; align-items: center; gap: 8px; }
.flex-1 { flex: 1; }
.spacer { flex: 1; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- Header ---------- */
.topbar {
  background: var(--header);
  color: #fff;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; margin-right: 18px; color: #fff; }
.brand-logo { width: 30px; height: 30px; border-radius: 7px; background: #fff; color: var(--primary); display: grid; place-items: center; font-weight: 800; }
.menu { display: flex; height: 100%; }
.menu-item { position: relative; height: 100%; }
.menu-item > a {
  display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 14px; color: #fff; font-weight: 500; cursor: pointer;
}
.menu-item > a:hover, .menu-item.active > a { background: rgba(255, 255, 255, .16); }
.menu-item .caret { font-size: 9px; opacity: .8; }
.submenu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 210px; background: #fff; border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15); padding: 6px 0;
}
.menu-item:hover .submenu { display: block; }
.submenu a { display: block; padding: 9px 16px; color: var(--text); }
.submenu a:hover { background: var(--primary-light); color: var(--primary); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar select {
  background: rgba(255, 255, 255, .15); color: #fff; border: 1px solid rgba(255, 255, 255, .35); border-radius: var(--radius); padding: 5px 8px;
}
.topbar select option { color: var(--text); }
.btn-sell {
  background: var(--success); color: #fff; border: 0; border-radius: var(--radius); padding: 8px 16px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
.btn-sell:hover { background: var(--success-dark); }
.user-menu { position: relative; }
.user-btn { background: transparent; border: 0; color: #fff; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius); }
.user-btn:hover { background: rgba(255, 255, 255, .16); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-menu .submenu { left: auto; right: 0; border-radius: var(--radius); top: calc(100% + 4px); }
.user-menu.open .submenu { display: block; }
.mobile-toggle { display: none; background: transparent; border: 0; color: #fff; font-size: 22px; cursor: pointer; }

/* ---------- Layout ---------- */
.page { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin-right: auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-body { padding: 16px; }
.card-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.card-head h3 { font-size: 15px; margin-right: auto; }
.layout-side { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.side-panel .card { margin-bottom: 12px; }
.side-panel h4 { font-size: 13px; margin-bottom: 8px; text-transform: uppercase; color: var(--muted); letter-spacing: .3px; }
.radio-list label { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: #f5f7fa; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-dark); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdecec; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-lg { padding: 12px 20px; font-size: 16px; font-weight: 600; }
.btn-icon { padding: 4px 8px; border: 0; background: transparent; color: var(--muted); }
.btn-icon:hover { color: var(--danger); background: #fdecec; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 10px; background: #fff; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 112, 244, .12); }
.input-sm { padding: 4px 8px; }
.input.num { text-align: right; }
textarea.input { resize: vertical; min-height: 60px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field label .req { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.search-box { position: relative; }
.search-box .input { padding-left: 32px; }
.search-box::before { content: "⌕"; position: absolute; left: 10px; top: 50%; transform: translateY(-52%); color: var(--muted); font-size: 17px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tab { padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; background: none; border-top: 0; border-left: 0; border-right: 0; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 99px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th { background: #f3f6fa; text-align: left; font-weight: 600; font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--row-hover); }
.table tfoot td { font-weight: 600; background: #fafbfc; }
.table .num { text-align: right; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-success { background: #e3f6eb; color: var(--success-dark); }
.badge-warning { background: #fff4db; color: #b97700; }
.badge-danger { background: #fde8e8; color: #c1272a; }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-muted { background: #eef0f3; color: var(--muted); }
.table-summary { display: flex; gap: 24px; padding: 10px 16px; border-top: 1px solid var(--border); background: #fafbfc; flex-wrap: wrap; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 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; font-size: 20px; flex-shrink: 0; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.kpi-sub { font-size: 12px; margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .bar { fill: var(--primary); transition: opacity .15s; }
.chart .bar:hover { opacity: .75; }
.chart .bar-profit { fill: #4fc3a1; }
.chart .grid-line { stroke: #edf0f3; }
.hbar { margin-bottom: 10px; }
.hbar-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; gap: 8px; }
.hbar-top span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 8px; background: #eef1f5; border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; background: linear-gradient(90deg, #0070f4, #44a2ff); border-radius: 99px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto; animation: fade .12s;
}
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); animation: pop .15s; }
.modal.lg { max-width: 920px; }
.modal.sm { max-width: 420px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h3 { font-size: 17px; margin-right: auto; }
.modal-close { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(-10px); opacity: 0; } }
.info-list { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 500; }

/* ---------- Toast ---------- */
#toasts { position: fixed; top: 64px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2933; color: #fff; padding: 11px 16px; border-radius: var(--radius); box-shadow: 0 8px 20px rgba(0, 0, 0, .2); min-width: 240px; max-width: 380px; animation: pop .2s; border-left: 4px solid var(--success); }
.toast.error { border-left-color: var(--danger); }

/* ---------- Product picker ---------- */
.picker { position: relative; }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .15); max-height: 360px; overflow-y: auto; z-index: 60;
}
.picker-item { padding: 8px 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #f1f3f5; }
.picker-item:last-child { border-bottom: 0; }
.picker-item.active, .picker-item:hover { background: var(--primary-light); }
.picker-item .pi-name { font-weight: 500; }
.picker-item .pi-sub { font-size: 12px; color: var(--muted); }
.picker-item .pi-price { margin-left: auto; text-align: right; font-weight: 600; white-space: nowrap; }
.thumb { width: 36px; height: 36px; border-radius: 6px; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; font-size: 13px; }

/* ---------- Document editor (nhập hàng, chuyển kho, kiểm kho) ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.doc-side .field { margin-bottom: 12px; }
.sum-row { display: flex; justify-content: space-between; padding: 6px 0; gap: 10px; align-items: center; }
.sum-row.total { font-size: 17px; font-weight: 700; border-top: 1px dashed var(--border); padding-top: 10px; margin-top: 4px; }
.sum-row .input { max-width: 160px; }
.qty-input { width: 80px; }
.price-input { width: 120px; }

/* ---------- POS ---------- */
.pos { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }
.pos-top { background: var(--header); padding: 8px 12px; display: flex; gap: 10px; align-items: center; color: #fff; }
.pos-top .picker { width: 420px; max-width: 45vw; }
.pos-top .input { border: 0; }
.pos-top .picker, .pos-top .picker .input { color: var(--text); }
.pos-tabs { display: flex; gap: 4px; align-items: flex-end; overflow-x: auto; }
.pos-tab { background: rgba(255, 255, 255, .18); color: #fff; padding: 6px 10px 6px 12px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; white-space: nowrap; border: 0; }
.pos-tab.active { background: #fff; color: var(--primary); font-weight: 600; }
.pos-tab .x { opacity: .6; font-size: 15px; }
.pos-tab .x:hover { opacity: 1; }
.pos-add-tab { background: transparent; border: 1px dashed rgba(255, 255, 255, .6); color: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.pos-top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.pos-top-right a { color: #fff; }
.pos-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 10px; padding: 10px; min-height: 0; }
.pos-left { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.pos-cart { flex: 1.3; overflow-y: auto; min-height: 160px; }
.pos-grid-wrap { flex: 1; display: flex; flex-direction: column; min-height: 160px; }
.pos-grid { flex: 1; overflow-y: auto; padding: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; align-content: start; }
.pos-prod { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; cursor: pointer; background: #fff; text-align: left; display: flex; flex-direction: column; gap: 4px; min-height: 86px; }
.pos-prod:hover { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(0, 112, 244, .12); }
.pos-prod .n { font-size: 13px; font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pos-prod .p { color: var(--primary); font-weight: 700; margin-top: auto; }
.pos-prod .s { font-size: 11px; color: var(--muted); }
.pos-prod.out { opacity: .55; }
.cart-line { display: grid; grid-template-columns: 28px minmax(0, 1fr) 118px 110px 110px 30px; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid #eef0f3; }
.cart-line:hover { background: var(--row-hover); }
.cart-line .ln-name { font-weight: 500; }
.cart-line .ln-code { font-size: 12px; color: var(--muted); }
.qty-ctl { display: flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.qty-ctl button { border: 0; background: #f3f6fa; width: 28px; height: 30px; cursor: pointer; font-size: 16px; }
.qty-ctl button:hover { background: var(--primary-light); }
.qty-ctl input { width: 100%; border: 0; text-align: center; outline: none; height: 30px; min-width: 0; }
.cart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--muted); gap: 8px; padding: 30px; }
.cart-empty .big { font-size: 42px; opacity: .4; }
.pos-right { display: flex; flex-direction: column; min-height: 0; }
.pos-right .card-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.pos-pay { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.pos-pay .btn { flex: 1; }
.pay-methods { display: flex; gap: 6px; margin: 6px 0; }
.pay-methods .chip { flex: 1; text-align: center; }
.cust-box { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--primary-light); }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 6px; }
.quick-cash .chip { font-size: 12px; padding: 3px 10px; }
.kbd { display: inline-block; font-size: 11px; padding: 0 5px; border-radius: 3px; background: rgba(0, 0, 0, .12); margin-left: 4px; font-weight: 500; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0058c4 0%, #0090ff 100%); padding: 16px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 12px; padding: 32px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.login-card .brand { color: var(--primary); justify-content: center; font-size: 24px; margin: 0 0 6px; }
.login-card .brand-logo { background: var(--primary); color: #fff; width: 40px; height: 40px; font-size: 22px; }
.brand-tagline { text-align: center; color: var(--primary); font-size: 13px; font-weight: 500; margin: -2px 0 10px; letter-spacing: .2px; }
.login-card p { text-align: center; margin: 0 0 22px; color: var(--muted); }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 11px; }
.login-error { color: var(--danger); margin-bottom: 10px; min-height: 20px; text-align: center; }

/* ---------- Tài khoản, gói dịch vụ ---------- */
.login-card.wide { max-width: 560px; }
.auth-tabs { justify-content: center; margin-bottom: 8px; }
.login-card .form-grid .field { margin-bottom: 0; }
.user-info { padding: 8px 16px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 13px; color: var(--text); }
.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: var(--radius); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.banner > span { flex: 1; min-width: 200px; }
.banner .btn { margin-left: auto; }
.banner-danger { background: #fde8e8; color: #9b1c1f; border: 1px solid #f5b5b6; }
.banner-warning { background: #fff4db; color: #8a5a00; border: 1px solid #f6d58a; }
.banner-info { background: var(--primary-light); color: #0b4fa8; border: 1px solid #bcd6fb; }
.banner-success { background: #e3f6eb; color: var(--success-dark); border: 1px solid #a8e0bf; }
.billing-top { display: grid; grid-template-columns: 1.2fr 1fr 1.2fr; gap: 16px; }
.wallet-card { background: linear-gradient(135deg, #0058c4, #1a8cff); color: #fff; display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.wallet-balance { font-size: 32px; font-weight: 700; }
.wallet-balance small { font-size: 16px; opacity: .8; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.plan-card { padding: 18px; display: flex; flex-direction: column; gap: 6px; position: relative; border: 2px solid transparent; }
.plan-card.current { border-color: var(--primary); }
.plan-card.lifetime { background: linear-gradient(160deg, #fffaf0, #fff 60%); border-color: #f6d58a; }
.plan-card.lifetime .plan-price { color: #b97700; }
.plan-tag { position: absolute; top: 12px; right: 12px; }
.plan-name { font-weight: 600; font-size: 16px; }
.plan-price { font-size: 26px; font-weight: 700; color: var(--primary); }
.plan-price small { font-size: 14px; }
.plan-desc { font-size: 13px; color: var(--muted); min-height: 18px; flex: 1; }
.switch { position: relative; width: 44px; height: 24px; display: inline-block; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cdd3da; border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }
.qr-layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.qr-box { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; place-items: center; min-height: 260px; }
.qr-box img { max-width: 100%; height: auto; }
.perm-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 16px; }
.perm-list label { display: flex; gap: 8px; align-items: center; }
.topbar.sys { background: #1f2a44; }
.code-box { font-family: Consolas, monospace; background: #f3f6fa; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; word-break: break-all; font-size: 13px; }

/* ---------- Ứng dụng điện thoại (PWA) ---------- */
.pos-search { display: flex; gap: 6px; align-items: center; }
.pos-search .search-box { flex: 1; }
.pos-scan { border: 0; background: #fff; border-radius: var(--radius); height: 36px; min-width: 40px; font-size: 18px; cursor: pointer; }
.pos-mtabs, .pos-mbar, .bottom-nav { display: none; }
.offline-bar { position: fixed; left: 0; right: 0; top: 0; z-index: 300; background: #9b1c1f; color: #fff; text-align: center; font-size: 13px; padding: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top)); }
.scan-region { width: 100%; min-height: 240px; background: #000; border-radius: 8px; overflow: hidden; }
.scan-region video { width: 100% !important; height: auto !important; display: block; }
.scan-status { margin-top: 8px; font-size: 13px; text-align: center; }
.scan-log { max-height: 110px; overflow-y: auto; font-size: 13px; margin-top: 6px; }
html.standalone .topbar, html.standalone .pos-top { padding-top: env(safe-area-inset-top); height: auto; min-height: 52px; }
* { -webkit-tap-highlight-color: rgba(0, 112, 244, .12); }

@media (max-width: 900px) {
  /* Thanh điều hướng dưới đáy */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: #fff; border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(0, 0, 0, .06);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 2px 6px; color: var(--muted); font-size: 18px; line-height: 1.1; }
  .bottom-nav a span { font-size: 11px; font-weight: 500; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a.bn-sell { color: #fff; background: var(--success); border-radius: 14px; margin: 4px 6px; padding: 5px 2px; }
  #view { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar .btn-sell { display: none; }
  .menu { max-height: calc(100vh - 52px - 64px); overflow-y: auto; }

  /* Màn hình bán hàng: chia tab Chọn hàng / Giỏ hàng */
  .pos-mtabs { display: grid; grid-template-columns: 1fr 1fr; background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40; }
  .pos-mtabs button { border: 0; background: none; padding: 11px 6px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; font-size: 14px; }
  .pos-mtabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
  .pos[data-mv="products"] .pos-cart, .pos[data-mv="products"] .pos-right { display: none; }
  .pos[data-mv="cart"] .pos-grid-wrap, .pos[data-mv="cart"] .pos-mbar { display: none; }
  .pos-body { padding: 8px; gap: 8px; }
  .pos-grid-wrap { min-height: 0; }
  .pos-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); padding: 8px; gap: 6px; overflow: visible; }
  .pos-prod { min-height: 78px; padding: 7px; }
  .pos-cart { flex: none; min-height: 120px; overflow: visible; }
  .pos-right .card-body { overflow: visible; }
  .pos-pay { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 10px rgba(0, 0, 0, .06); z-index: 5; }
  .pos-mbar {
    display: flex; justify-content: space-between; align-items: center; gap: 10px; position: fixed; left: 10px; right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 50; border: 0; border-radius: 12px; background: var(--primary); color: #fff;
    padding: 13px 16px; font-size: 15px; box-shadow: 0 8px 24px rgba(0, 112, 244, .35); cursor: pointer;
  }
  .pos-mbar.bump { animation: bump .3s; }
  .pos[data-mv="products"] .pos-body { padding-bottom: 80px; }
  .pos-top-right span { display: none; }
  .pos-top .pos-tabs { order: 4; width: 100%; }
  .cart-line { padding: 10px; }
  .cart-line .btn-icon { font-size: 18px; }
  .qty-ctl button { width: 34px; height: 34px; }
  .kbd { display: none; }

  /* Ô nhập cỡ chữ 16px để iPhone không tự phóng to khi bấm vào */
  .input, select.input, textarea.input, .qty-ctl input { font-size: 16px; }
  .table td, .table th { padding: 10px; }
}
@keyframes bump { 50% { transform: scale(1.04); } }

@media (max-width: 600px) {
  /* Hộp thoại toàn màn hình trên điện thoại */
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal, .modal.lg, .modal.sm { max-width: none; border-radius: 0; min-height: 100%; display: flex; flex-direction: column; }
  .modal-head { position: sticky; top: 0; background: #fff; z-index: 2; padding-top: calc(14px + env(safe-area-inset-top)); }
  .modal-body { flex: 1; }
  .modal-foot { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 19px; width: 100%; }
  .page-head .btn { flex: 1; }
  #toasts { left: 12px; right: 12px; top: calc(60px + env(safe-area-inset-top)); }
  .toast { max-width: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .dash-grid, .doc-layout, .billing-top, .qr-layout { grid-template-columns: minmax(0, 1fr); }
  .pos-body { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 900px) {
  .mobile-toggle { display: block; }
  .menu { display: none; position: absolute; top: 52px; left: 0; right: 0; flex-direction: column; background: var(--header); height: auto; }
  .menu.open { display: flex; }
  .menu-item { height: auto; }
  .menu-item > a { padding: 12px 16px; }
  .menu .submenu { position: static; box-shadow: none; display: block; background: rgba(255, 255, 255, .08); border-radius: 0; padding: 0; }
  .menu .submenu a { color: #fff; padding-left: 32px; }
  .topbar-right .wh-select, .topbar-right .user-name { display: none; }
  .topbar { padding: 0 10px; }
  .brand { margin-right: 0; min-width: 0; }
  .brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; font-size: 16px; }
  .btn-sell { white-space: nowrap; padding: 7px 10px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 10px; gap: 8px; }
  .kpi-icon { width: 34px; height: 34px; font-size: 16px; }
  .kpi-value { font-size: 17px; }
  .layout-side { grid-template-columns: minmax(0, 1fr); }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pos { height: auto; min-height: 100vh; }
  .pos-body { grid-template-columns: minmax(0, 1fr); }
  .pos-top { flex-wrap: wrap; }
  .pos-top .picker { width: 100%; max-width: none; order: 3; }
  .cart-line { grid-template-columns: 22px minmax(0, 1fr) 100px 28px; }
  .cart-line .ln-price, .cart-line .ln-total-col { display: none; }
}
@media (max-width: 600px) {
  .page { padding: 12px; }
  .form-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .info-list { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
}
