:root {
  --red: #c8102e;
  --red-dark: #9e0c24;
  --red-soft: #fdecee;
  --ink: #1d1d1f;
  --ink-2: #55565b;
  --ink-3: #8a8b90;
  --line: #e7e5e2;
  --bg: #f6f4f1;
  --card: #ffffff;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --blue: #2563c9;
  --blue-soft: #e8f0fc;
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
.hidden { display: none !important; }

/* ---------- khung ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px; min-height: 54px;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { background: none; border: 0; color: #fff; font-size: 26px; padding: 0 6px 0 0; line-height: 1; }
.topbar .who { font-size: 12px; opacity: .7; text-align: right; line-height: 1.2; }
main { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 760px; margin: 0 auto; }

.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
}
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--ink-3); font-size: 11.5px; font-weight: 600; position: relative; }
.nav a .ic { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .75; }
.nav a.on { color: var(--red); }
.nav a.on .ic { filter: none; opacity: 1; }
.nav .dot { position: absolute; top: 6px; left: 50%; margin-left: 8px; background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px; }

/* ---------- thành phần ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--ink-2); font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px;
  padding: 0 18px; min-height: 48px; font-weight: 650; font-size: 16px; background: var(--ink); color: #fff; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .45; }
.btn.red { background: var(--red); }
.btn.ok { background: var(--ok); }
.btn.ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn.warn { background: var(--warn); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.grow { flex: 1; }
.muted { color: var(--ink-3); font-size: 14px; }
.small { font-size: 13px; }
.center { text-align: center; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 48px; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; font-size: 16px;
}
.input:focus { outline: none; border-color: var(--ink); }
textarea.input { min-height: 76px; resize: vertical; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip.alert.on { background: var(--red); border-color: var(--red); }

.search { position: relative; margin-bottom: 12px; }
.search input { padding-left: 40px; }
.search::before { content: "🔍"; position: absolute; left: 13px; top: 13px; font-size: 16px; opacity: .55; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.DRAFT { background: #eee; color: var(--ink-2); }
.badge.PENDING_ACC, .badge.PENDING_OWNER { background: var(--warn-soft); color: var(--warn); }
.badge.APPROVED { background: var(--ok-soft); color: var(--ok); }
.badge.RETURNED { background: var(--blue-soft); color: var(--blue); }
.badge.REJECTED, .badge.CANCELLED { background: var(--red-soft); color: var(--red); }
.badge.IN { background: var(--ok-soft); color: var(--ok); }
.badge.OUT { background: var(--red-soft); color: var(--red); }

/* ---------- lưới mặt hàng ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.tile { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); position: relative; border: 2px solid transparent; text-align: left; padding: 0; cursor: pointer; }
.tile.sel { border-color: var(--red); }
.tile .ph { aspect-ratio: 4/3; background: #efece8; display: grid; place-items: center; font-size: 44px; overflow: hidden; }
.tile .ph img { width: 100%; height: 100%; object-fit: cover; }
.tile .b { padding: 9px 10px 11px; }
.tile .n { font-weight: 650; font-size: 14.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 36px; }
.tile .q { margin-top: 4px; font-size: 20px; font-weight: 750; }
.tile .q small { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.tile.low .q { color: var(--red); }
.tile .flag { position: absolute; top: 8px; left: 8px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.tile .count { position: absolute; top: 8px; right: 8px; background: var(--red); color: #fff; font-weight: 800; min-width: 28px; height: 28px; border-radius: 14px; display: grid; place-items: center; padding: 0 8px; }

/* ---------- danh sách ---------- */
.list { background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.li { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.li:last-child { border-bottom: 0; }
.li .t { font-weight: 650; }
.li .s { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.li .r { text-align: right; flex: none; }
.thumb { width: 52px; height: 52px; border-radius: 10px; background: #efece8; display: grid; place-items: center; font-size: 26px; overflow: hidden; flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- dòng phiếu ---------- */
.line { background: #fff; border-radius: var(--radius); padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border: 2px solid transparent; }
.line.review { border-color: var(--red); }
.line.confirmed { border-color: #f2c4a6; }
.line .head { display: flex; gap: 10px; align-items: center; }
.line .head .nm { font-weight: 700; flex: 1; }
.line .raw { font-size: 13px; color: var(--ink-2); background: var(--bg); border-radius: 8px; padding: 6px 9px; margin-top: 8px; }
.reasons { background: var(--red-soft); color: var(--red-dark); border-radius: 10px; padding: 8px 10px; margin-top: 8px; font-size: 14px; }
.reasons ul { margin: 4px 0 0; padding-left: 18px; }
.reasons.done { background: var(--warn-soft); color: var(--warn); }
.cands { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cands button { border: 1.5px solid var(--red); color: var(--red); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.fields label span { font-size: 12px; font-weight: 600; color: var(--ink-3); display: block; margin-bottom: 3px; }
.fields .input { min-height: 44px; }
.stepper { display: flex; align-items: stretch; }
.stepper button { width: 44px; border: 1.5px solid var(--line); background: #fff; font-size: 22px; font-weight: 700; }
.stepper button:first-child { border-radius: 12px 0 0 12px; border-right: 0; }
.stepper button:last-child { border-radius: 0 12px 12px 0; border-left: 0; }
.stepper input { border-radius: 0; text-align: center; min-width: 0; }
.x { background: none; border: 0; font-size: 20px; color: var(--ink-3); padding: 4px 8px; }

.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos .p { width: 86px; height: 86px; border-radius: 10px; overflow: hidden; background: #efece8; position: relative; display: grid; place-items: center; font-size: 30px; }
.photos .p img { width: 100%; height: 100%; object-fit: cover; }
.photos .p .del { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 24px; height: 24px; font-size: 14px; }
.photos .add { border: 2px dashed var(--line); background: #fff; color: var(--ink-2); font-size: 13px; font-weight: 600; text-align: center; line-height: 1.2; cursor: pointer; }
.photos .add b { display: block; font-size: 26px; }

.notice { border-radius: 12px; padding: 11px 13px; margin-bottom: 12px; font-size: 14.5px; }
.notice.red { background: var(--red-soft); color: var(--red-dark); }
.notice.warn { background: var(--warn-soft); color: #7a4a00; }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.blue { background: var(--blue-soft); color: #1b4a96; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- tiến trình duyệt ---------- */
.steps { display: flex; align-items: flex-start; margin: 4px 0 14px; }
.step { flex: 1; text-align: center; position: relative; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.step .c { width: 30px; height: 30px; border-radius: 50%; background: #e4e1dd; color: #fff; display: grid; place-items: center; margin: 0 auto 5px; font-size: 15px; position: relative; z-index: 1; }
.step::before { content: ""; position: absolute; top: 15px; left: -50%; width: 100%; height: 3px; background: #e4e1dd; }
.step:first-child::before { display: none; }
.step.done .c, .step.done::before { background: var(--ok); }
.step.done { color: var(--ok); }
.step.now .c { background: var(--warn); }
.step.now { color: var(--warn); }
.step.bad .c { background: var(--red); }
.step.bad { color: var(--red); }

.hist { font-size: 14px; }
.hist .h { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.hist .h:last-child { border-bottom: 0; }
.hist .h em { color: var(--ink-2); font-style: normal; display: block; margin-top: 2px; }

.actionbar { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 25; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 8px; }
.actionbar .btn { flex: 1; }
.actionbar-inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; width: 100%; }

.bigchoice { display: grid; gap: 12px; }
.bigchoice button { background: #fff; border: 0; border-radius: 18px; padding: 20px 18px; text-align: left; display: flex; gap: 16px; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,.07); cursor: pointer; }
.bigchoice .ic { font-size: 40px; width: 62px; height: 62px; border-radius: 16px; display: grid; place-items: center; background: var(--red-soft); flex: none; }
.bigchoice b { font-size: 18px; display: block; }
.bigchoice span { color: var(--ink-3); font-size: 14px; }

/* ---------- hộp thoại ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 90vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: var(--safe-b); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet .sh { padding: 14px 16px 8px; display: flex; align-items: center; gap: 8px; }
.sheet .sh h2 { margin: 0; font-size: 18px; flex: 1; }
.sheet .sb { overflow-y: auto; padding: 4px 14px 16px; }
.sheet .sf { padding: 10px 14px 14px; display: flex; gap: 8px; border-top: 1px solid var(--line); background: #fff; }
.sheet .sf .btn { flex: 1; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 84px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 80; font-weight: 600; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }
.loading { position: fixed; inset: 0; background: rgba(255,255,255,.85); z-index: 90; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-weight: 650; text-align: center; padding: 20px; }
.spin { width: 42px; height: 42px; border: 4px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: s 0.8s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }

.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { text-align: center; margin-bottom: 26px; }
.login .logo .m { width: 76px; height: 76px; border-radius: 22px; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 38px; margin: 0 auto 12px; }
.login h1 { margin: 0; font-size: 22px; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
table.t th, table.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; white-space: normal; }
table.t th { font-size: 12px; color: var(--ink-3); text-transform: uppercase; position: sticky; top: 0; background: #fff; }
.tablewrap { overflow-x: auto; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.big { font-size: 34px; font-weight: 800; }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-3); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.sum { display: flex; justify-content: space-between; font-weight: 700; padding: 10px 2px; }
table.split { width: 100%; margin-top: 6px; border-collapse: collapse; font-size: 14px; }
table.split td { padding: 3px 0; }
table.split td:last-child { text-align: right; white-space: nowrap; }
.step.skip .c { background: #cfccc7; }
