/* In tem giá – Khang Baby */
@font-face { font-family: "Be Vietnam Pro"; font-weight: 500; font-display: swap; src: url("../fonts/BeVietnamPro-Medium.ttf") format("truetype"); }
@font-face { font-family: "Be Vietnam Pro"; font-weight: 700; font-display: swap; src: url("../fonts/BeVietnamPro-Bold.ttf") format("truetype"); }
@font-face { font-family: "Be Vietnam Pro"; font-weight: 800; font-display: swap; src: url("../fonts/BeVietnamPro-ExtraBold.ttf") format("truetype"); }

:root {
  --bg: #F6F0F3;
  --surface: #FFFFFF;
  --desk: #E9DDE3;
  --ink: #2E2126;
  --muted: #75646B;
  --line: #E6D9DF;
  --wine: #A3214F;
  --wine-dark: #861A40;
  --pink: #F03E8C;
  --blush: #FBE6EE;
  --ok: #1B7A52;
  --warn: #9A5600;
  --warn-bg: #FFF3DC;
  --bad: #C2263A;
  --bad-bg: #FDE9EB;
  --r: 12px;
  --shadow: 0 10px 30px rgba(87, 33, 55, .14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 500 16px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2 { margin: 0; font-weight: 800; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }

/* ---------- nút, ô nhập ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--r); cursor: pointer;
  border: 1.5px solid var(--wine); background: var(--surface); color: var(--wine);
  font-weight: 700; white-space: nowrap;
}
.btn:hover { background: var(--blush); }
.btn.primary { background: var(--wine); color: #fff; }
.btn.primary:hover { background: var(--wine-dark); border-color: var(--wine-dark); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.big { min-height: 56px; font-size: 18px; flex: 1; }
.btn.quiet { border-color: var(--line); color: var(--muted); }
.btn.quiet:hover { background: var(--bg); color: var(--ink); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: default; }
.link { border: 0; background: none; padding: 0; color: var(--wine); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

input[type=text], input[type=search], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 10px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--wine); box-shadow: 0 0 0 3px var(--blush); }
label { display: block; font-size: 14px; font-weight: 700; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 6px; color: var(--ink); font-weight: 500; font-size: 16px; }
.chk { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); font-weight: 500; cursor: pointer; padding: 6px 0; }
.chk input { width: 20px; height: 20px; accent-color: var(--wine); margin: 0; flex: none; }
.hint { font-size: 13.5px; color: var(--muted); }

/* ---------- thanh trên ---------- */
.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 24px;
  padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 20px; color: var(--wine); }
.brand img { display: block; height: 44px; width: auto; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0; background: none; padding: 12px 14px; cursor: pointer; font-weight: 700; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -9px; padding-bottom: 18px;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--wine); border-bottom-color: var(--wine); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 20px; min-width: 0; }
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-width: 0; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.status.warn::before { background: #E39A1B; }
.status.bad::before { background: var(--bad); }
.status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; white-space: nowrap; }

.banner { padding: 10px 24px; background: var(--warn-bg); color: #6B3D00; border-bottom: 1px solid #F0D9A8; font-size: 15px; }

/* ---------- trang in ---------- */
.view { max-width: 1360px; margin: 0 auto; padding: 24px; }
.print-view { display: grid; grid-template-columns: minmax(0, 1fr) 452px; gap: 28px; align-items: start; }

.search label { font-size: 19px; font-weight: 800; color: var(--ink); margin-bottom: 10px; }
.search-box { position: relative; }
.search-box > svg { position: absolute; left: 18px; top: 18px; width: 24px; height: 24px; fill: none; stroke: var(--wine); stroke-width: 2.2; stroke-linecap: round; pointer-events: none; }
#q {
  min-height: 60px; padding: 0 18px 0 54px; font-size: 19px; border: 2px solid var(--wine); border-radius: 16px;
  box-shadow: 0 4px 0 var(--blush);
}
#q:focus { box-shadow: 0 0 0 4px var(--blush); }
#q::placeholder { color: #A8979E; }
.search .hint { margin-top: 10px; }

.results {
  position: absolute; left: 0; right: 0; top: 66px; z-index: 20; max-height: min(62vh, 560px); overflow: auto;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
}
.res {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; width: 100%; text-align: left;
  padding: 10px 12px; border: 0; background: none; border-radius: 10px; cursor: pointer;
}
.res:hover, .res.sel { background: var(--blush); }
.res-name { font-weight: 700; }
.res-price { font-weight: 800; color: var(--wine); white-space: nowrap; }
.res-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13.5px; color: var(--muted); }
.res-none { padding: 14px; color: var(--muted); }
.tag {
  display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: var(--blush); color: var(--wine); white-space: nowrap;
}
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.ok { background: #E4F4EC; color: var(--ok); }

.list-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin: 30px 0 12px; }
.count { color: var(--muted); font-size: 15px; }
.list-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.list:empty { display: none; }
.row {
  display: grid; align-items: start; gap: 8px 12px; padding: 14px 16px; border-top: 1px solid var(--line);
  grid-template-columns: minmax(0, 1fr) 150px 132px 40px;
  grid-template-areas: "main price qty del" "sub sub sub sub" "notes notes notes notes";
}
.role-admin .row {
  grid-template-columns: 24px minmax(0, 1fr) 150px 132px 40px;
  grid-template-areas: "pick main price qty del" ". sub sub sub sub" ". notes notes notes notes";
}
.row:first-child { border-top: 0; }
.row.is-bad { background: #FFF8F8; }
.row.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background: var(--blush); } to { background: transparent; } }
.pick { grid-area: pick; width: 20px; height: 20px; margin: 12px 0 0; accent-color: var(--wine); }
.r-main { grid-area: main; min-width: 0; }
.r-name { font-weight: 700; font-size: 16.5px; }
div.r-name { padding: 10px 0 2px; overflow-wrap: anywhere; }
input.r-name { font-weight: 700; }
.r-sub { grid-area: sub; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-width: 0; }
.r-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; font-size: 13.5px; color: var(--muted); }
input.r-note { flex: 1 1 240px; width: auto; min-height: 36px; padding: 5px 12px; font-size: 14.5px; background: #FDF9FB; }
.r-note-text { font-size: 14px; color: var(--muted); }
.r-price { grid-area: price; display: flex; flex-direction: column; gap: 6px; }
.r-price strong { display: block; padding: 9px 0; text-align: right; font-size: 18px; font-weight: 800; color: var(--wine); white-space: nowrap; }
.money { position: relative; }
.money input { padding-right: 30px; text-align: right; font-weight: 800; color: var(--wine); }
.money::after { content: "₫"; position: absolute; right: 12px; top: 10px; font-weight: 700; color: var(--muted); }
.money.old input { font-weight: 500; color: var(--muted); min-height: 38px; font-size: 14.5px; }
.money.old::after { top: 7px; }
.qty { grid-area: qty; display: grid; grid-template-columns: 40px 1fr 40px; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.qty button { border: 0; background: var(--bg); font-size: 20px; font-weight: 700; cursor: pointer; min-height: 41px; color: var(--wine); }
.qty button:hover { background: var(--blush); }
.qty input { border: 0; border-radius: 0; min-height: 41px; padding: 0; text-align: center; font-weight: 800; font-size: 17px; -moz-appearance: textfield; }
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.del { grid-area: del; width: 40px; height: 44px; border: 0; background: none; border-radius: 10px; cursor: pointer; color: var(--muted); font-size: 18px; }
.del:hover { background: var(--bad-bg); color: var(--bad); }
.r-notes { grid-area: notes; display: grid; gap: 6px; }
.r-notes:empty { display: none; }
.note { padding: 7px 12px; border-radius: 10px; font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.note.bad { background: var(--bad-bg); color: #8C1727; }
.note.warn { background: var(--warn-bg); color: #6B3D00; }
.note.info { background: var(--bg); color: var(--muted); }

.empty { padding: 34px 24px; border: 2px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }
.empty p + p { margin-top: 6px; max-width: 46ch; margin-inline: auto; }

/* ---------- cột bên phải: mẫu, tờ giấy, nút in ---------- */
.out {
  position: sticky; top: 86px; display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--line); border-radius: 18px; max-height: calc(100vh - 104px); overflow: hidden;
}
.out-scroll { display: grid; gap: 12px; padding: 20px; overflow: auto; min-height: 0; }
.tpls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tpl {
  display: grid; gap: 6px; padding: 8px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface);
  cursor: pointer; text-align: left; align-content: start;
}
.tpl:hover { border-color: #D7B9C6; }
.tpl[aria-checked=true] { border-color: var(--wine); background: var(--blush); }
.tpl-thumb { height: 52px; display: flex; align-items: center; justify-content: center; }
.tpl-thumb svg { max-width: 100%; max-height: 100%; display: block; box-shadow: 0 1px 4px rgba(46, 33, 38, .18); }
.tpl-name { font-size: 13px; font-weight: 700; line-height: 1.25; }
.tpl-hint { font-size: 12px; color: var(--muted); line-height: 1.25; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.desk { background: var(--desk); border-radius: 14px; padding: 18px; display: flex; justify-content: center; }
.sheet { width: 100%; background: #fff; box-shadow: 0 2px 2px rgba(46, 33, 38, .12), 0 14px 28px rgba(87, 33, 55, .18); line-height: 0; }
.sheet svg { display: block; width: 100%; height: auto; }
.sheet.ghost svg { opacity: .38; }
.sheet.single { box-shadow: 0 2px 8px rgba(46, 33, 38, .25); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 14px; color: var(--muted); }
.pager .btn { min-width: 40px; font-size: 20px; }
.go { display: flex; gap: 10px; padding: 14px 20px 18px; background: var(--surface); border-top: 1px solid var(--line); flex: none; }

/* ---------- khu quản lý ---------- */
.admin-view { max-width: 1120px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.lead { margin-top: 6px; color: var(--muted); max-width: 72ch; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: grid; gap: 14px; }
.settings { display: grid; gap: 16px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; align-items: end; }
.save-bar { display: flex; justify-content: flex-end; }
.card > .btn { justify-self: start; }
.kv-status { display: grid; gap: 4px; font-size: 15px; }
.kv-status strong { font-weight: 800; }

.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.tbl th { text-align: left; font-size: 13.5px; color: var(--muted); font-weight: 700; padding: 12px 14px; background: #FBF7F9; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: top; font-size: 15px; }
.tbl tr:first-child td { border-top: 0; }
.tbl .num { text-align: right; white-space: nowrap; font-weight: 700; }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .acts .btn { margin-left: 6px; }
.codes { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.code { padding: 1px 8px; border-radius: 6px; background: var(--bg); font-size: 13px; }
.sub { font-size: 13.5px; color: var(--muted); }
details.log-items summary { cursor: pointer; color: var(--wine); font-weight: 700; font-size: 14px; }
details.log-items ul { margin: 8px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); }

/* ---------- hộp thoại ---------- */
.dlg { width: min(620px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; box-shadow: var(--shadow); color: var(--ink); }
.dlg::backdrop { background: rgba(46, 33, 38, .45); }
.dlg-in { padding: 24px; display: grid; gap: 16px; }
.dlg h2 { font-size: 21px; }
.dlg-body { display: grid; gap: 14px; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.dlg ul.plain { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.dlg ul.plain li { padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: 15px; }
.members { display: grid; gap: 6px; }
.member { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 8px 12px; background: var(--bg); border-radius: 10px; font-size: 14.5px; }
.member b { font-weight: 800; color: var(--wine); white-space: nowrap; }
.member .del { grid-area: auto; width: 30px; height: 30px; font-size: 15px; }
.radio { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; font-weight: 500; color: var(--ink); cursor: pointer; }
.radio input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--wine); flex: none; }
.radio.off { color: var(--muted); cursor: default; }
.mini-results { border: 1.5px solid var(--line); border-radius: 10px; max-height: 190px; overflow: auto; padding: 4px; }
.mini-results:empty { display: none; }

.toasts { position: fixed; right: 16px; top: 78px; z-index: 100; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 15px; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); }
.toast.warn { background: #7A4700; }
.toast.ok { background: var(--ok); }

/* ---------- đăng nhập ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-logo { display: block; width: 212px; height: auto; margin: 0 auto 14px; }
.login h1 { text-align: center; color: var(--wine); }
.login-sub { text-align: center; color: var(--muted); margin: 8px 0 20px; }
.login form { display: grid; gap: 8px; }
.login form label { margin-top: 8px; }
.login form .btn { margin-top: 16px; min-height: 52px; font-size: 17px; }
.login-foot { margin-top: 18px; font-size: 13.5px; color: var(--muted); text-align: center; }
.msg { padding: 10px 14px; border-radius: 10px; font-size: 15px; margin-bottom: 8px; }
.msg.bad { background: var(--bad-bg); color: #8C1727; }

/* ---------- màn hình hẹp ---------- */
@media (max-width: 1080px) {
  .print-view { grid-template-columns: minmax(0, 1fr); }
  .out { position: static; max-height: none; overflow: visible; }
  .out-scroll { overflow: visible; }
  .go { position: sticky; bottom: 0; border-radius: 0 0 18px 18px; }
  .tpls { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .desk { padding: 14px; }
  .sheet { max-width: 520px; }
}
@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 6px 16px; padding: 8px 14px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tabs button { margin-bottom: -9px; white-space: nowrap; }
  .status span { max-width: 44vw; }
  .view { padding: 16px 14px 28px; }
  .tpls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { grid-template-columns: minmax(0, 1fr) 40px; grid-template-areas: "main del" "price price" "sub sub" "qty qty" "notes notes"; }
  .role-admin .row { grid-template-columns: 24px minmax(0, 1fr) 40px; grid-template-areas: "pick main del" ". price price" ". sub sub" ". qty qty" ". notes notes"; }
  .r-price strong { text-align: left; }
  .qty { max-width: 190px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; }
  .tbl thead { display: none; }
  .tbl td { border-top: 0; padding: 4px 14px; }
  .tbl tr { border-top: 1px solid var(--line); padding: 10px 0; }
  .tbl .num, .tbl .acts { text-align: left; }
  .tbl .acts .btn { margin: 6px 6px 0 0; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- in ---------- */
#print-root { display: none; }
@media print {
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block !important; }
  .p-sheet { overflow: hidden; break-after: page; page-break-after: always; break-inside: avoid; }
  .p-sheet:last-child { break-after: auto; page-break-after: auto; }
  .p-sheet svg { display: block; width: 100%; height: 100%; }
}
