:root {
  --green: #1d6b4c; --green-dark: #14523a; --green-soft: #e1f1e8;
  --bg: #f4f7f5; --surface: #ffffff; --text: #15211b; --muted: #5b6a62; --line: #dbe4de;
  --amber: #8a5a00; --amber-soft: #fdf1d6; --red: #b42318; --red-soft: #fde7e5; --grey-soft: #eceff0;
  --radius: 16px; --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
#app { min-height: 100%; display: flex; flex-direction: column; }
#view { flex: 1; padding: calc(16px + var(--safe-top)) 16px calc(var(--nav-h) + var(--safe-bottom) + 24px); max-width: 560px; width: 100%; margin: 0 auto; }
#view.no-nav { padding-bottom: calc(24px + var(--safe-bottom)); }
h1 { font-size: 24px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 20px 0 8px; } p { margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; } .mt { margin-top: 16px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
:focus-visible { outline: 3px solid #7ab99c; outline-offset: 2px; }

/* nút */
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 56px; padding: 12px 18px; border-radius: 14px;
  font-weight: 650; font-size: 17px; background: var(--green); color: #fff; text-align: center; }
.btn:active { background: var(--green-dark); }
.btn.outline { background: var(--surface); color: var(--green); border: 2px solid var(--green); }
.btn.ghost { background: transparent; color: var(--green); min-height: 44px; font-weight: 600; }
.btn.danger { background: var(--surface); color: var(--red); border: 2px solid var(--red); }
.btn.big { min-height: 120px; flex-direction: column; font-size: 22px; border-radius: 20px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn small { font-weight: 500; font-size: 13px; opacity: .9; }
.row { display: flex; gap: 12px; } .row > * { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* thẻ, chip */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.tap { width: 100%; text-align: left; }
.stat b { display: block; font-size: 34px; line-height: 1.1; } .stat span { color: var(--muted); font-size: 14px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--grey-soft); color: #3b4650; }
.chip.green { background: var(--green-soft); color: var(--green-dark); } .chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.banner { padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.banner.amber { background: var(--amber-soft); color: var(--amber); } .banner.red { background: var(--red-soft); color: var(--red); }
.banner.green { background: var(--green-soft); color: var(--green-dark); }
.banner button { background: none; color: inherit; text-decoration: underline; font-weight: 700; padding: 0 0 0 6px; }

/* biểu mẫu */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
.field { width: 100%; min-height: 54px; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 17px; }
.field:focus { border-color: var(--green); outline: none; }
textarea.field { min-height: 110px; resize: vertical; }
.error { color: var(--red); font-weight: 600; margin-top: 10px; min-height: 1.4em; }
.logo { width: 76px; height: 76px; border-radius: 20px; display: block; margin: 8px auto 12px; }

/* phiếu */
.slip-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.kv { display: grid; grid-template-columns: 112px 1fr; gap: 6px 12px; margin: 12px 0 0; font-size: 15px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.progress { height: 14px; background: var(--grey-soft); border-radius: 999px; overflow: hidden; margin: 10px 0 4px; }
.progress > i { display: block; height: 100%; width: var(--w, 0%); background: var(--green); border-radius: 999px; }
.stepper { display: flex; align-items: stretch; gap: 10px; margin: 6px 0 14px; }
.stepper button { width: 64px; min-height: 64px; border-radius: 14px; background: var(--surface); border: 2px solid var(--green); color: var(--green); font-size: 30px; font-weight: 700; }
.stepper input { flex: 1; min-width: 0; text-align: center; font-size: 30px; font-weight: 700; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); }
.log { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; } .log li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.tabs { display: flex; background: var(--grey-soft); border-radius: 14px; padding: 4px; margin: 12px 0; }
.tabs button { flex: 1; min-height: 46px; background: transparent; border-radius: 11px; font-weight: 650; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--green-dark); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.item { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.item b { font-size: 17px; } .item .meta { color: var(--muted); font-size: 14px; margin: 4px 0 8px; word-break: break-word; }
.result { text-align: center; padding-top: 28px; } .result .icon { width: 96px; height: 96px; border-radius: 50%; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; font-size: 52px; font-weight: 700; }
.result .icon.ok { background: var(--green-soft); color: var(--green); } .result .icon.warn { background: var(--amber-soft); color: var(--amber); } .result .icon.bad { background: var(--red-soft); color: var(--red); }

/* màn quét */
.scan { position: fixed; inset: 0; background: #000; z-index: 5; display: flex; flex-direction: column; }
.scan video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan .shade { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.scan .frame { position: absolute; left: 50%; top: 42%; width: min(72vw, 320px); aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan .frame::before, .scan .frame::after { content: ""; position: absolute; width: 46px; height: 46px; border: 5px solid #5fd49b; }
.scan .frame::before { left: -3px; top: -3px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.scan .frame::after { right: -3px; bottom: -3px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.scan .top { position: relative; padding: calc(14px + var(--safe-top)) 16px 0; display: flex; justify-content: space-between; align-items: center; color: #fff; }
.scan .hint { position: absolute; left: 0; right: 0; top: calc(42% + min(36vw, 160px) + 28px); text-align: center; color: #fff; font-weight: 600; padding: 0 24px; text-shadow: 0 1px 3px #000; }
.scan .bottom { position: absolute; left: 16px; right: 16px; bottom: calc(18px + var(--safe-bottom)); display: grid; gap: 10px; }
.scan .round { width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; font-size: 22px; }
.scan .btn.glass { background: rgba(255,255,255,.92); color: var(--green-dark); }
.scan .flash { position: absolute; inset: 0; background: #5fd49b; opacity: 0; pointer-events: none; transition: opacity .4s; } .scan .flash.on { opacity: .45; transition: none; }
.scan .msg { position: absolute; left: 16px; right: 16px; top: calc(70px + var(--safe-top)); background: var(--red-soft); color: var(--red); padding: 12px 14px; border-radius: 12px; font-weight: 650; }

/* điều hướng dưới */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.nav[hidden] { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: var(--nav-h); gap: 2px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 650; }
.nav a svg { width: 26px; height: 26px; } .nav a[aria-current="page"] { color: var(--green); }
.nav a.scan-tab { color: #fff; } .nav a.scan-tab span.disc { width: 56px; height: 56px; margin-top: -22px; border-radius: 50%; background: var(--green); display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 10px rgba(20,82,58,.45); }
.nav a.scan-tab em { font-style: normal; color: var(--muted); } .nav a.scan-tab[aria-current="page"] em { color: var(--green); }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px); z-index: 20; background: #1f2a24; color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; text-align: center; max-width: 520px; margin: 0 auto; }
.toast[hidden] { display: none; }
.guide ol { padding-left: 20px; margin: 8px 0; } .guide li { margin: 6px 0; }
.spinner { width: 30px; height: 30px; border: 4px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ===== kho v2: tiêu đề, lưới, form tạo phiếu, thanh loading ===== */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.topbar .who { color: var(--green-dark); font-weight: 650; text-decoration: none; background: var(--green-soft); padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.head h1 { margin: 0; }
.btn.sm { width: auto; min-height: 44px; padding: 8px 16px; font-size: 15px; border-radius: 12px; white-space: nowrap; }
.btn.back, .back { width: auto; min-height: 40px; justify-content: flex-start; padding-left: 0; }
.row.wrap { flex-wrap: wrap; } .row.wrap > * { flex: 1 1 200px; min-width: 0; }
.grid { display: grid; grid-template-columns: 1fr; gap: 10px; } .grid .item { margin: 0; }
select.field { appearance: auto; }
.addbar { display: flex; gap: 10px; align-items: flex-start; }
.searchwrap { position: relative; flex: 1; min-width: 0; }
.addbar .field { margin: 0; }
.sugg { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 6; background: var(--surface); border: 2px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.14); max-height: 320px; overflow: auto; }
.sugg[hidden] { display: none; }
.sugg button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; background: transparent; text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 52px; }
.sugg button:hover, .sugg button:focus-visible { background: var(--green-soft); }
.pad { padding: 12px 14px; }
.ln { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-top: 10px; flex-wrap: wrap; }
.ln.bad { border-color: var(--red); background: #fff8f7; } .ln.focus { border-color: var(--green); box-shadow: 0 0 0 3px #bfe3d0; }
.ln-name { flex: 1 1 200px; min-width: 0; display: flex; flex-direction: column; gap: 2px; word-break: break-word; }
.ln-qty { display: flex; align-items: center; gap: 6px; }
.ln-qty input, .qin { width: 84px; min-height: 48px; text-align: center; font-size: 18px; font-weight: 700; border: 2px solid var(--line); border-radius: 10px; background: var(--surface); }
.mini { width: 44px; min-height: 48px; border-radius: 10px; background: var(--surface); border: 2px solid var(--green); color: var(--green); font-size: 24px; font-weight: 700; }
.x { width: 40px; height: 40px; border-radius: 50%; background: var(--grey-soft); color: #555; font-size: 16px; }
.ln-act { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.qrbox { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.qrbox svg { max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.loading { position: fixed; inset: 0; z-index: 50; background: rgba(21,33,27,.55); display: flex; align-items: center; justify-content: center; padding: 24px; }
.loading .box { width: min(420px, 100%); background: var(--surface); border-radius: 20px; padding: 26px 22px; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.loading .lt { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.loading .bar { height: 14px; border-radius: 999px; background: var(--grey-soft); overflow: hidden; position: relative; }
.loading .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #2c8f67, #5fd49b); border-radius: 999px; transition: width .25s ease-out; position: relative; overflow: hidden; }
.loading .bar i::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); transform: translateX(-100%); animation: shine 1.2s infinite; }
.loading .ls { margin-top: 14px; color: var(--muted); font-size: 15px; min-height: 1.4em; }
@keyframes shine { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .loading .bar i::after { animation: none; } }
.nav .brand, .nav .side-only { display: none; }

/* ===== máy tính / máy tính bảng: thanh bên trái, nội dung rộng hơn ===== */
@media (min-width: 900px) {
  #view { max-width: 980px; margin-left: 240px; margin-right: auto; padding: 24px 32px 48px; }
  #view.no-nav { margin: 0 auto; max-width: 560px; }
  .nav { top: 0; right: auto; width: 240px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 18px 12px; gap: 4px; justify-content: flex-start; }
  .nav .brand { display: block; font-weight: 800; font-size: 20px; color: var(--green-dark); padding: 6px 12px 18px; line-height: 1.15; }
  .nav .brand small { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
  .nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: 12px; font-size: 16px; }
  .nav a[aria-current="page"] { background: var(--green-soft); }
  .nav a.scan-tab { color: var(--muted); } .nav a.scan-tab span.disc { width: 26px; height: 26px; margin: 0; background: transparent; box-shadow: none; }
  .nav a.scan-tab span.disc svg { stroke: currentColor; width: 26px; height: 26px; } .nav a.scan-tab { flex-direction: row; } .nav a.scan-tab em { color: inherit; font-size: 16px; font-weight: 650; order: 2; }
  .nav a.scan-tab[aria-current="page"] { color: var(--green); }
  .nav .side-only { display: flex; margin-top: auto; }
  .topbar { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .toast { left: 256px; bottom: 24px; }
  .scan { left: 0; }
}
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(3, 1fr); } }

/* ===== in phiếu ===== */
@media print {
  .nav, .noprint, .toast, .topbar, .btn.back, .loading { display: none !important; }
  body, html { background: #fff; }
  #view { margin: 0; max-width: none; padding: 0; }
  .card, .ln { border-color: #999; break-inside: avoid; }
  .chip { border: 1px solid #999; background: #fff; color: #000; }
}

/* thẻ mặt hàng có nút nhanh */
.item[role="link"] { cursor: pointer; }
.quick { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.quick button { flex: 1 1 auto; min-height: 44px; padding: 0 14px; border-radius: 10px; background: var(--green-soft); color: var(--green-dark); font-weight: 650; }
.quick button[disabled] { opacity: .4; }
.quick button[data-q="XK"] { background: var(--amber-soft); color: var(--amber); }
.quick button[data-q="EDIT"] { background: var(--grey-soft); color: #3b4650; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 14px; }
.check input { width: 22px; height: 22px; }
#stats { margin-bottom: 4px; } #stats .stat { padding: 10px 12px; } #stats .stat b { font-size: 26px; }

.row.wrap > div { display: flex; flex-direction: column; justify-content: flex-end; }
.row.wrap > div .field { margin-top: auto; }
