:root {
  --bg: #F4F6F9; --card: #FFFFFF; --ink: #1E2630; --muted: #5E6B7A; --line: #DDE3EA;
  --brand: #0F5FD7; --brand-ink: #FFFFFF; --ok: #1E8E4E; --warn: #B26A00; --bad: #C62828;
  --demo: #7A1FA2; --radius: 12px; --tap: 44px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; max-width: 100%; }
p, h1, h2, h3, div, span, li, td { overflow-wrap: anywhere; }

.demo-banner {
  position: sticky; top: 0; z-index: 30; background: var(--demo); color: #fff;
  font-size: 12px; font-weight: 600; text-align: center; padding: 6px 10px;
}
.demo-banner.test { background: var(--warn); }
/* v3.4.6 PWA: mất mạng — không xếp hàng offline, chỉ báo cho người dùng */
.net-banner { position: sticky; top: 0; z-index: 31; background: var(--bad); color: #fff; font-size: 13px;
  font-weight: 600; text-align: center; padding: 8px 10px; }
.net-banner[hidden] { display: none; }
.install summary { font-weight: 600; cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
.install ol { margin: 6px 0 0; padding-left: 20px; }
@media (display-mode: standalone) { .install { display: none; } }
.app { max-width: 520px; margin: 0 auto; padding: 12px 12px 120px; padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; }
.topbar h1 { font-size: 19px; margin: 0; flex: 1; min-width: 0; }
.back { min-width: var(--tap); min-height: var(--tap); border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; font-size: 18px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }

.btn { min-height: var(--tap); padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn.bad { background: #fff; color: var(--bad); border-color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { min-height: 96px; text-align: left; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--card); cursor: pointer; display: flex; flex-direction: column; justify-content: space-between; }
.tile b { font-size: 16px; }
.tile .badge { align-self: flex-start; }

.persona { width: 100%; text-align: left; display: block; }
.persona + .persona { margin-top: 8px; }

.search { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--card); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { min-height: 38px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.item { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; width: 100%;
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
  margin-bottom: 8px; cursor: pointer; }
.item img { width: 64px; height: 64px; border-radius: 10px; display: block; }
.item .name { font-weight: 600; }
.item .add { min-width: var(--tap); min-height: var(--tap); border-radius: 10px; background: var(--brand); color: #fff;
  border: 0; font-size: 22px; font-weight: 700; display: flex; align-items: center; justify-content: center; line-height: 1; }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 16px; max-height: 88vh; overflow-y: auto; max-width: 520px; margin: 0 auto; }
.sizes { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.size { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; }
.size.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.stepper { display: grid; grid-template-columns: var(--tap) 1fr var(--tap); gap: 8px; align-items: center; }
.stepper button { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 20px; }
.stepper input { min-height: var(--tap); text-align: center; border: 1px solid var(--line); border-radius: 10px; width: 100%; }

.cartbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.cartbar .inner { max-width: 520px; margin: 0 auto; }

label.f { display: block; font-size: 14px; font-weight: 600; margin: 10px 0 4px; }
.f-input { width: 100%; min-height: var(--tap); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  background: #fff; }
textarea.f-input { min-height: 80px; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: #E8EDF3; color: var(--ink); }
.badge.draft { background: #ECEFF3; }
.badge.submitted { background: #FFF1D6; color: var(--warn); }
.badge.approved, .badge.ordered, .badge.awaiting_purchase { background: #E3EEFF; color: var(--brand); }
.badge.partially_received { background: #FFF1D6; color: var(--warn); }
.badge.fulfilled, .badge.received { background: #E2F4E9; color: var(--ok); }
.badge.rejected { background: #FDE6E6; color: var(--bad); }
.badge.demo { background: #F3E5F8; color: var(--demo); }

.line { border-top: 1px solid var(--line); padding: 8px 0; }
.line:first-child { border-top: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.qtys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; font-size: 12px; margin-top: 6px; }
.qtys div { background: #F4F6F9; border-radius: 8px; padding: 4px; text-align: center; }
.qtys b { display: block; font-size: 15px; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 3px solid var(--line); padding: 4px 0 8px 10px; font-size: 13px; }
.err { background: #FDE6E6; color: var(--bad); border-radius: 10px; padding: 10px; margin: 8px 0; font-size: 14px; }
.okmsg { background: #E2F4E9; color: var(--ok); border-radius: 10px; padding: 10px; margin: 8px 0; font-size: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.hidden { display: none !important; }

/* v3: tăng ca */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 > div { min-width: 0; }
.f-input[type="date"], .f-input[type="time"] { min-width: 0; -webkit-appearance: none; appearance: none; }
a.btn { display: block; text-align: center; text-decoration: none; color: inherit; box-sizing: border-box; }
a.btn.primary { color: var(--brand-ink); }
.badge.plan_submitted, .badge.actual_submitted { background: #FFF1D6; color: var(--warn); }
.badge.plan_manager_approved, .badge.actual_verified { background: #E3EEFF; color: var(--brand); }
.badge.plan_confirmed { background: #E3EEFF; color: var(--brand); }
.badge.plan_returned, .badge.actual_returned { background: #FDE6E6; color: var(--bad); }
.badge.finalized { background: #E2F4E9; color: var(--ok); }
.badge.cancelled { background: #ECEFF3; }

/* v3.4.6 MVP vật tư: Vật tư khác, danh mục rỗng, người xác nhận */
.other-btn { margin: 10px 0 12px; min-height: 52px; border-style: dashed; border-width: 2px; font-size: 16px; }
.other-ico { width: 44px; height: 44px; flex: 0 0 44px; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: #EEF3FB; color: var(--brand); font-size: 20px; }
.empty-catalog { border-style: dashed; }
#review-who { background: #F7FAFF; }
/* Dòng trong giỏ/kiểm tra trước khi gửi: tên chiếm trọn hàng đầu; stepper + nút xoá xuống hàng hai (không ép tên về 0 ở 390px) */
.line.row { flex-wrap: wrap; }
.line.row > .grow { flex: 1 1 calc(100% - 60px); }
.line.row > .stepper { flex: 1 1 150px; max-width: 220px; margin-left: 52px; }
