:root {
  --nav: #1f2a6b;
  --nav-2: #2a3a8f;
  --nav-text: #cfd6ff;
  --primary: #2b4acb;
  --primary-2: #203aa6;
  --primary-soft: #eef1ff;
  --ok: #16874a;
  --ok-soft: #e7f6ee;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --danger: #c93030;
  --danger-soft: #fdecec;
  --bg: #eef1f6;
  --panel: #ffffff;
  --line: #dde2ec;
  --text: #1d2433;
  --muted: #667085;
  --radius: 8px;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
h4 { margin: 16px 0 8px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- thành phần chung ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px; line-height: 1.2; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-2); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9c6ff; border-color: var(--primary); }
input[readonly] { background: #f5f6f9; }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { color: var(--text); }
label.chk { cursor: pointer; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: 1 / -1; }
.pet-row { display: grid; grid-template-columns: 2fr 1fr 1.5fr 1fr; gap: 6px; margin-bottom: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--danger); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.tag.svc { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th, table.t td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.t th { background: #f6f7fb; font-weight: 600; font-size: 13px; position: sticky; top: 0; z-index: 1; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f5f7ff; }
table.t tr.cancelled td { color: var(--muted); text-decoration: line-through; }
table.t tr.subtotal td { background: #fafbfd; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .v.ok { color: var(--ok); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.empty.big { font-size: 16px; line-height: 1.8; padding: 50px 20px; }

/* hộp thoại, thông báo */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: min(560px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(900px, 100%); }
.modal header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 16px; flex: 1; }
.modal .body { padding: 16px; overflow: auto; }
.modal footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
#toast-root { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 70; }
.toast { background: #1d2433; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* đăng nhập */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1f2a6b, #3b5bdb); padding: 16px; }
.auth .box { background: #fff; border-radius: 12px; padding: 28px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; }
.auth h1 { margin: 0; font-size: 22px; }
.auth .btn { padding: 11px; font-size: 15px; }

/* ---------- trang quản trị ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.sidebar { background: var(--nav); color: var(--nav-text); display: flex; flex-direction: column; }
.brand { padding: 14px 16px; font-size: 18px; font-weight: 700; color: #fff; display: flex; flex-direction: column; }
.brand .small { font-weight: 400; color: var(--nav-text); }
.pos-link { margin: 0 12px 10px; padding: 10px; border-radius: 8px; background: #fff; color: var(--nav); font-weight: 600; text-align: center; text-decoration: none; }
.pos-link:hover { background: var(--primary-soft); }
.sidebar nav { flex: 1; overflow: auto; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 10px 16px; color: var(--nav-text); text-decoration: none; }
.sidebar nav a:hover { background: var(--nav-2); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar .me { padding: 12px 16px; border-top: 1px solid var(--nav-2); font-size: 13px; }
.sidebar .me b { color: #fff; display: block; }
.sidebar .me .btn { margin-top: 8px; width: 100%; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 17px; margin: 0; flex: 1; white-space: nowrap; }
.content { flex: 1; overflow: auto; padding: 16px; }
.menu-btn { display: none; }

/* ---------- màn hình BÁN HÀNG ---------- */
body.pos-page { overflow: hidden; }
.pos-app { display: flex; flex-direction: column; height: 100vh; }
.pos-head { background: var(--nav); color: #fff; display: flex; align-items: flex-end; gap: 10px; padding: 6px 10px 0; min-height: 46px; }
.pos-logo { font-weight: 700; font-size: 16px; padding-bottom: 10px; white-space: nowrap; }
.pos-tabs { display: flex; gap: 3px; align-items: flex-end; overflow-x: auto; flex: 1; min-width: 0; }
.pos-tab { padding: 8px 12px; background: var(--nav-2); color: var(--nav-text); border-radius: 8px 8px 0 0; cursor: pointer; display: flex; gap: 6px; align-items: center; white-space: nowrap; border: 0; }
.pos-tab:hover { color: #fff; }
.pos-tab.active { background: var(--bg); color: var(--primary); font-weight: 600; }
.pos-tab.add { font-size: 16px; padding: 6px 12px; }
.pos-tab .x { opacity: .6; padding: 0 2px; }
.pos-tab .x:hover { opacity: 1; color: var(--danger); }
.badge { background: var(--primary); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
.pos-tab:not(.active) .badge { background: #fff; color: var(--nav); }
.pos-head-right { display: flex; gap: 10px; align-items: center; padding-bottom: 8px; white-space: nowrap; }
.pos-head-right .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.pos-head-right .btn:hover { background: var(--nav-2); }

.pos-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 10px; padding: 10px; min-height: 0; }
.pos-left { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; position: relative; }
.pos-search { position: relative; background: #fff; border: 2px solid var(--primary); border-radius: var(--radius); padding: 6px 8px; display: flex; gap: 8px; align-items: center; }
.pos-search .search-ico { font-size: 18px; }
.pos-search input.q { flex: 1; font-size: 16px; border: 0; outline: 0; padding: 6px 2px; }
.pos-search select { max-width: 200px; }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.15); z-index: 30; max-height: 360px; overflow: auto; }
.suggest > div { padding: 9px 12px; display: flex; gap: 10px; align-items: center; cursor: pointer; border-bottom: 1px solid #f0f2f6; }
.suggest > div.sel, .suggest > div:hover { background: var(--primary-soft); }
.suggest > div[data-new] { color: var(--primary); font-weight: 600; }

.pos-lines { flex: 1; min-height: 120px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.line { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.line.need { background: #fffaf0; }
.line.flash { animation: flash 0.8s; }
@keyframes flash { from { background: #dfe6ff; } to { background: transparent; } }
.line-main { display: grid; grid-template-columns: 26px minmax(0, 1fr) 124px 110px 110px 34px; gap: 8px; align-items: center; }
.line-no { color: var(--muted); text-align: center; }
.line-name { font-weight: 600; line-height: 1.3; }
.line-price, .line-amt { text-align: right; font-variant-numeric: tabular-nums; }
.line-amt { font-weight: 700; font-size: 15px; }
.line input.money { width: 100%; text-align: right; }
.stepper { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.stepper button { border: 0; background: #f4f6fa; width: 34px; cursor: pointer; font-size: 16px; }
.stepper button:hover { background: var(--primary-soft); }
.stepper input { border: 0; border-radius: 0; width: 100%; text-align: center; padding: 6px 2px; }
.line-sub { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0 0 34px; }
.line-sub label { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.line-sub select { padding: 4px 6px; max-width: 190px; }
.line-sub select.empty-sel { border-color: var(--warn); background: var(--warn-soft); }
.line-sub input.money { width: 100px; padding: 4px 6px; }

.pos-grid-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; height: 36%; min-height: 170px; display: flex; flex-direction: column; }
.chips { display: flex; gap: 4px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; overflow: auto; padding-top: 8px; align-content: start; }
.tile { border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; background: #fafbff; display: flex; flex-direction: column; gap: 3px; min-height: 78px; text-align: left; }
.tile.service { background: #f4fbf7; }
.tile:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(43,74,203,.15); }
.tile:active { transform: scale(.98); }
.tile .n { font-size: 13px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .meta { font-size: 11px; color: var(--muted); }
.tile .p { font-weight: 700; color: var(--ok); margin-top: auto; }

.pos-right { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pos-right .sec { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cust-search { position: relative; }
.cust-search input { width: 100%; }
.cust-box { background: #f6f7fb; border-radius: 6px; padding: 8px; margin-top: 8px; font-size: 13px; display: flex; gap: 6px; align-items: flex-start; }
.sum { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; gap: 8px; }
.sum input.money { width: 130px; text-align: right; }
.sum.big { font-size: 20px; font-weight: 800; color: var(--primary); padding-top: 6px; }
.pos-right .pay { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.pay-row { display: flex; align-items: center; gap: 8px; }
.pay-row span { width: 115px; font-size: 13px; }
.pay-row input { flex: 1; text-align: right; font-size: 17px; font-weight: 600; padding: 8px 10px; }
.quick-cash { display: flex; gap: 6px; flex-wrap: wrap; padding-left: 123px; }
.qr-box { text-align: center; border: 1px dashed var(--line); border-radius: 8px; padding: 6px; }
.qr-box img { width: 200px; max-width: 100%; }
.pay textarea { resize: vertical; }
.pos-right .actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.pos-right .actions .btn { padding: 12px; font-size: 15px; font-weight: 700; flex-direction: column; }
.pos-right .actions .btn .small { font-weight: 400; opacity: .8; }
.done-banner { background: var(--ok); color: #fff; border-radius: 8px; padding: 10px 14px; font-size: 15px; }
.done-banner .big-change { font-size: 18px; font-weight: 800; background: rgba(255,255,255,.2); padding: 2px 8px; border-radius: 6px; }

/* ---------- in hóa đơn khổ 80mm ---------- */
#print-root { display: none; }
@media print {
  @page { size: 80mm auto; margin: 3mm; }
  body * { visibility: hidden; }
  body.pos-page { overflow: visible; }
  #print-root, #print-root * { visibility: visible; }
  #print-root { display: block; position: absolute; left: 0; top: 0; width: 74mm; font-size: 12px; color: #000; font-family: Arial, sans-serif; }
  #print-root h2 { font-size: 15px; text-align: center; margin: 0 0 2px; }
  #print-root .c { text-align: center; }
  #print-root .r { text-align: right; }
  #print-root table { width: 100%; border-collapse: collapse; }
  #print-root td { padding: 2px 0; vertical-align: top; }
  #print-root hr { border: 0; border-top: 1px dashed #000; margin: 4px 0; }
}

/* ---------- màn hình nhỏ ---------- */
@media (max-width: 1150px) {
  .pos-body { grid-template-columns: minmax(0, 1fr) 330px; }
  .line-main { grid-template-columns: 22px minmax(0, 1fr) 110px 90px 95px 30px; }
  .pos-logo { display: none; }
}
@media (max-width: 900px) {
  body.pos-page { overflow: auto; }
  .pos-app { height: auto; min-height: 100vh; }
  .pos-body { grid-template-columns: 1fr; }
  .pos-lines { min-height: 200px; max-height: 50vh; }
  .pos-grid-wrap { height: 300px; }
  .pos-head-right #clock { display: none; }
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 10px; }
  .line-main { grid-template-columns: minmax(0, 1fr) 100px 80px 30px; }
  .line-main .line-no, .line-main .line-price { display: none; }
  .line-sub { margin-left: 0; }
  .form-grid, .pet-row { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
}
