:root {
  --primary: #1463d8;
  --primary-600: #0f52b8;
  --primary-50: #eaf2ff;
  --bg: #f4f6fa;
  --surface: #fff;
  --border: #e2e7ef;
  --border-strong: #cfd6e2;
  --text: #172033;
  --muted: #667085;
  --green: #0f7b55; --green-bg: #e6f6ef;
  --amber: #a15c07; --amber-bg: #fff4e0;
  --red: #c9301f; --red-bg: #fdecea;
  --gray-bg: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 232px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.text-green { color: var(--green); } .text-red { color: var(--red); } .text-amber { color: var(--amber); }

/* ---------- Khung ứng dụng ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .8rem; letter-spacing: .02em; }
.brand b { display: block; font-size: 1.05rem; letter-spacing: .03em; }
.brand span { display: block; font-size: .75rem; color: var(--muted); }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: #344054; font-weight: 500; }
.nav a:hover { background: var(--gray-bg); }
.nav a.active { background: var(--primary-50); color: var(--primary); }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); font-size: .85rem; }
.sidebar-foot .who { font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { flex: 1; font-size: 1.15rem; }
.menu-btn { display: none; }
.content { padding: 20px 24px 40px; max-width: 1400px; width: 100%; }
.backdrop { display: none; }

/* ---------- Thành phần ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--gray-bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { color: var(--red); border-color: #f3c4bf; }
.btn-danger:hover { background: var(--red-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; min-height: 30px; font-size: .85rem; }
.btn-lg { padding: 12px 18px; font-size: 1.05rem; min-height: 48px; }
.btn-block { width: 100%; }
.icon-btn { padding: 6px; min-height: 32px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-b { padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dash-grid { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.45rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar .spacer { flex: 1; }

input, select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; min-height: 38px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #93b9f5; outline-offset: 0; border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.toolbar input, .toolbar select { width: auto; }
.toolbar input.grow { width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: .85rem; font-weight: 500; color: #344054; }
.field .hint { font-size: .78rem; color: var(--muted); }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }

.table-wrap { overflow-x: auto; }
@media (min-width: 601px) { .table-wrap > table { min-width: 720px; } }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; font-weight: 600; color: var(--muted); background: #fafbfd; white-space: nowrap; }
tbody tr:hover { background: #fafcff; }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.gray { background: var(--gray-bg); color: #475467; }
.badge.blue { background: var(--primary-50); color: var(--primary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .title { font-weight: 500; }

/* ---------- Biểu đồ ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--primary); }
.chart .bar:hover { fill: var(--primary-600); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--border); }

/* ---------- Modal & thông báo ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 14px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(16, 24, 40, .25); }
.modal.lg { max-width: 820px; }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1d2939; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow); max-width: 360px; animation: pop .18s ease-out; }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #eaf2ff 0%, #f4f6fa 55%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 18px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.demo-accounts { margin-top: 16px; font-size: .82rem; color: var(--muted); background: var(--gray-bg); border-radius: 8px; padding: 10px 12px; }
.demo-accounts code { color: var(--text); }
.error-text { color: var(--red); font-size: .88rem; min-height: 1.2em; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.pos-search { display: flex; gap: 8px; margin-bottom: 10px; }
.pos-search input { font-size: 1.02rem; min-height: 44px; }
.product-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); margin-top: 12px; }
.p-card { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; cursor: pointer; font: inherit; color: inherit; display: flex; flex-direction: column; gap: 6px; min-height: 104px; }
.p-card:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.p-card:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; border-color: var(--border); }
.p-card .name { font-weight: 500; font-size: .92rem; line-height: 1.3; flex: 1; }
.p-card .price { font-weight: 650; color: var(--primary); }
.p-card .stock { font-size: .78rem; color: var(--muted); }
.cart { display: flex; flex-direction: column; }
.cart-lines { overflow-y: auto; flex: 1; min-height: 120px; max-height: 50vh; }
@media (min-height: 820px) and (min-width: 901px) {
  .cart { position: sticky; top: 76px; max-height: calc(100vh - 96px); }
  .cart-lines { max-height: none; }
}
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.cart-line .name { font-weight: 500; font-size: .92rem; }
.cart-line .meta { font-size: .8rem; color: var(--muted); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.qty button { border: 0; background: var(--gray-bg); width: 32px; height: 32px; font-size: 1.1rem; cursor: pointer; }
.qty input { width: 52px; border: 0; border-radius: 0; text-align: center; min-height: 32px; padding: 0; }
.cart-sum { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 9px; }
.sum-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sum-row.total { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
.sum-row input { width: 150px; text-align: right; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 4px; font: inherit; font-size: .88rem; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.active { background: var(--primary); color: #fff; }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; }
.customer-pick { position: relative; }
.dropdown { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-height: 260px; overflow-y: auto; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; font: inherit; cursor: pointer; }
.dropdown button:hover { background: var(--primary-50); }
.cart-bar { display: none; }

/* ---------- Phiếu nhập ---------- */
.line-table input { min-width: 90px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .pos { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; }
  .layout.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .4); z-index: 25; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px 14px 90px; }
  .pos { grid-template-columns: minmax(0, 1fr); }
  .cart { position: static; max-height: none; }
  .cart-bar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); align-items: center; justify-content: space-between; gap: 10px;
  }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none; }
}
@media (max-width: 600px) {
  :root { font-size: 14.5px; }
  .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 1.15rem; }
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th, td { padding: 9px 8px; }
  .toolbar > * { flex: 1 1 auto; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: 14px 14px 0 0; max-height: 94vh; overflow-y: auto; }
}
@media print {
  .sidebar, .topbar, .toolbar, .cart-bar, #toasts { display: none !important; }
}
