:root {
  --brand: #0f766e;
  --brand-soft: color-mix(in srgb, var(--brand) 12%, white);
  --bg: #f3f6f5;
  --card: #fff;
  --text: #1f2a2a;
  --muted: #6b7a78;
  --line: #dfe7e5;
  --danger: #c0392b;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  font-size: 15px; color: var(--text); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- layout */
.topbar {
  position: sticky; top: 0; z-index: 20; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand img { height: 30px; border-radius: 6px; background: #fff; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.2); }
.logo.big { width: 56px; height: 56px; font-size: 28px; background: var(--brand); color: #fff; border-radius: 14px; }
.who { display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.shell { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 220px; flex-shrink: 0; padding: 16px 10px; background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar a, .bottomnav a { text-decoration: none; color: var(--text); }
.sidebar a { display: flex; gap: 10px; padding: 10px 12px; border-radius: 8px; }
.sidebar a span { width: 18px; text-align: center; color: var(--muted); }
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sidebar a.active span { color: var(--brand); }
.content { flex: 1; min-width: 0; padding: 20px; max-width: 1280px; }
.bottomnav { display: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.soft { background: var(--brand-soft); border-color: transparent; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.grid { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { margin: 0; flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; font: inherit; font-weight: 600; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.btn.lg { padding: 14px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--brand-soft); color: var(--brand); }
.flash.error { background: #fdecea; color: var(--danger); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 12px; }
.seg input { display: none; }
.seg label { margin: 0; padding: 10px 6px; text-align: center; border: 1px solid var(--line); border-radius: 8px; color: var(--text); cursor: pointer; font-weight: 600; background: #fff; }
.seg input:checked + label { background: var(--brand); color: #fff; border-color: var(--brand); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--bg); }
.badge.IN { background: #e3f4ea; color: #1e7b45; }
.badge.OUT { background: #fdeee4; color: #b0531b; }
.badge.TRANSFER { background: #e6eefb; color: #2a5bb3; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f6f9f8; font-weight: 600; color: var(--muted); font-size: .8rem; white-space: nowrap; }
tbody tr:hover { background: #fafcfb; }
tfoot td { font-weight: 700; background: #f6f9f8; }
table.wide { min-width: 960px; }
table.wide td { white-space: nowrap; }
.grouphead th { text-align: center; border-left: 1px solid var(--line); }

/* ---------- scan screen */
.scan-wrap { max-width: 560px; }
#reader { border-radius: 10px; overflow: hidden; margin-top: 10px; }
/* Khung camera: khi trống chỉ thu chiều cao (không display:none) – thư viện quét lấy chiều rộng khung
   lúc bật camera, nếu khung đang ẩn thì hình xem trước rộng 0px (camera chạy nhưng không thấy hình). */
#reader:empty { height: 0; margin: 0; }
#reader video { width: 100% !important; height: auto !important; display: block; }
.suggest { border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; background: #fff; max-height: 260px; overflow: auto; }
.suggest:empty { display: none; }
.suggest div { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest div:last-child { border-bottom: 0; }
.suggest div:hover { background: var(--bg); }
.item { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.item:last-child { border-bottom: 0; }
.item-top { display: flex; justify-content: space-between; gap: 8px; }
.item-name { font-weight: 600; }
.item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stepper button { width: 40px; height: 40px; border: 0; background: var(--bg); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 72px; margin: 0; border: 0; border-radius: 0; text-align: center; padding: 8px 4px; }
.warn { color: var(--danger); font-size: .8rem; }
.item .req { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; }
.item .req input { width: 130px; margin: 0; padding: 6px 10px; }
.total-bar {
  position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: #fff; border-top: 1px solid var(--line); padding: 12px 0; margin-top: 8px;
}
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- document (phiếu, báo cáo) */
.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.doc-head { border-bottom: 2px solid var(--brand); padding-bottom: 10px; margin-bottom: 18px; display: flex; gap: 12px; }
.doc-head img { height: 48px; }
.doc-head b { color: var(--brand); }
.doc-title { text-align: center; margin: 12px 0 18px; }
.doc-title h2 { font-size: 1.4rem; margin: 0; letter-spacing: .5px; }
.doc-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 20px; background: #f6f9f8; border-radius: 8px; padding: 14px; margin-bottom: 18px; }
.doc-info small { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.signs { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin-top: 36px; min-height: 110px; }
.signs i { display: block; font-size: .8rem; color: var(--muted); }

/* ---------- workflow, trạng thái, tiện ích */
.nav-group { margin: 14px 12px 4px; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
/* Chưa dùng đơn giá (KHO_PRICES=0): ẩn mọi ô đơn giá / giá trị / thành tiền */
.no-prices .val { display: none !important; }
.user-link { color: #fff; text-decoration: none; }
.user-link:hover { text-decoration: underline; }
tr.muted td { color: var(--muted); }
.pill { padding: 3px 10px; border-radius: 99px; background: rgba(255,255,255,.18); font-size: .8rem; }
.status { display: inline-block; white-space: nowrap; padding: 2px 10px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: #eef2f1; color: #44514f; vertical-align: middle; }
.st-CHECKING, .st-COUNTED { background: #fff4d6; color: #8a6200; }
.st-CONFIRMED, .st-APPROVED { background: #e6eefb; color: #2a5bb3; }
.st-POSTED, .st-APPLIED { background: #e3f4ea; color: #1e7b45; }
.st-LOCKED { background: #e5e7eb; color: #1f2937; }
.st-CANCELLED { background: #fdecea; color: var(--danger); text-decoration: line-through; }
.st-COUNTING { background: var(--brand-soft); color: var(--brand); }
.badge.k-NK, .badge.k-INIT { background: #e3f4ea; color: #1e7b45; }
.badge.k-XK { background: #fdeee4; color: #b0531b; }
.badge.k-CK { background: #e6eefb; color: #2a5bb3; }
.badge.k-KK, .badge.k-DC { background: #f3e8fd; color: #7a3db8; }
.tag { display: inline-block; margin: 2px 6px 2px 0; padding: 2px 8px; border-radius: 6px; background: var(--bg); font-size: .8rem; text-decoration: none; color: var(--text); }
.pos { color: #1e7b45; } .neg { color: var(--danger); }
td.wrap, .wrap { white-space: normal !important; min-width: 180px; }
.steps { display: flex; list-style: none; padding: 0; margin: 0 0 14px; gap: 4px; flex-wrap: wrap; }
.steps li { flex: 1; min-width: 90px; text-align: center; padding: 8px 6px; background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: .85rem; color: var(--muted); }
.steps li.done { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.steps li.now { background: var(--brand); color: #fff; font-weight: 700; border-color: var(--brand); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text); background: #fff; border: 1px solid var(--line); font-size: .9rem; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs a .badge { background: rgba(0,0,0,.08); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 10px; }
.kpis > div { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.kpis small { display: block; color: var(--muted); font-size: .75rem; }
.kpis b { font-size: 1.05rem; word-break: break-word; }
.wf { display: flex; flex-direction: column; gap: 8px; }
.wf input { margin: 0; }
details.refs { margin: 4px 0 8px; }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; margin: 6px 0; }
.line-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.line-extra label { margin: 0; }
.line-extra input { padding: 6px 10px; }
.part-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.part-head .kpis { flex: 1; margin: 0; }
tr.bal td { background: #f6f9f8; }
tr.hit td { background: #fff4d6 !important; transition: background .3s; }
tr.saved .cnt { border-color: #1e7b45; }
.print-only { display: none; }
.vt05 { max-width: none; }
.vt05 .vt-table { font-size: 12px; }

/* ---------- Mẫu 02-VT */
.vt02 { font-family: "Times New Roman", Times, serif; font-size: 14px; color: #000; max-width: 900px; }
.vt-top { display: flex; justify-content: space-between; gap: 16px; }
.vt-top > div:last-child { min-width: 260px; }
.vt-title { font-size: 1.5rem; margin: 22px 0 4px; letter-spacing: 0; }
.vt-meta { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin-bottom: 12px; }
.vt-meta > div:first-child { grid-column: 2; }
.vt-meta > div:last-child { padding-left: 30px; }
.vt-lines div { margin: 3px 0; }
.vt-2col { display: flex; gap: 40px; }
.vt-table { margin: 10px 0; font-size: 13px; }
.vt-table th, .vt-table td { border: 1px solid #000; color: #000; padding: 4px 6px; background: none; vertical-align: middle; }
.vt-table th { text-align: center; white-space: normal; font-size: 13px; }
.vt-letters td { text-align: center; }
.vt-table tbody td:nth-child(3) { white-space: nowrap; }
.vt-total td { font-weight: 700; }
.vt-date { text-align: right; margin: 14px 0 4px; padding-right: 20px; }
.vt-signs { display: grid; grid-template-columns: repeat(5, 1fr); text-align: center; gap: 6px; }
.vt-signs i { display: block; font-size: 12px; min-height: 32px; }
.vt-signs span { display: block; margin-top: 70px; font-weight: 700; }

/* ---------- QR labels */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.label { border: 1px dashed #9aa; border-radius: 8px; padding: 10px; text-align: center; background: #fff; break-inside: avoid; }
.label .qr { display: flex; justify-content: center; margin: 4px 0 6px; }
.label .code { font-weight: 700; font-family: Consolas, monospace; }
.label .name { font-size: .8rem; color: var(--muted); }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, var(--brand-soft), var(--bg)); }
.login { width: 100%; max-width: 380px; padding: 28px 24px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand img { height: 56px; }
.login-brand h1 { margin-top: 10px; }

/* ---------- responsive: điện thoại */
@media (max-width: 760px) {
  .sidebar, .hide-sm, .desk-only { display: none !important; }
  .content { padding: 12px 12px 84px; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: #fff;
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: .68rem; text-align: center; }
  .bottomnav a span { font-size: 1.15rem; }
  .bottomnav a.active { color: var(--brand); font-weight: 700; }
  .doc { padding: 14px; }
  .total-bar { bottom: 64px; }
  .vt-top, .vt-2col { flex-direction: column; gap: 6px; }
  .vt-meta { grid-template-columns: 1fr; }
  .vt-meta > div:first-child { grid-column: auto; }
  .vt-meta > div:last-child { padding-left: 0; text-align: center; }
  .vt-signs { grid-template-columns: repeat(2, 1fr); row-gap: 20px; }
  .vt-signs span { margin-top: 40px; }
}

/* ---------- in ấn */
@media print {
  .no-print, .topbar, .sidebar, .bottomnav, .flash { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .doc, .card { border: 0; padding: 0; }
  .label { border: 1px dashed #666; }
  table { font-size: 11px; }
  @page { margin: 12mm; }
}

/* Quét ngoại tuyến */
.net-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.net-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #b0b8b7; vertical-align: middle; }
.net-dot.on { background: #1e9e5a; }
.net-dot.off { background: #d68910; }
.net-dot.login { background: var(--danger); }
.qstatus { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: #fff4e0; color: #9a5b00; }
.qstatus.sent { background: var(--brand-soft); color: var(--brand); }
.qstatus.error { background: #fdecea; color: var(--danger); }
.offline-ok { color: #1e7a4c; margin: -4px 0 12px; }
.offline-bad { background: #fdecea; color: var(--danger); padding: 10px 14px; border-radius: 8px; margin: -4px 0 12px; }

/* ---------- Tổng quan (trang chủ) */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: var(--text); }
.stat:hover { border-color: var(--brand); }
.stat small { color: var(--muted); font-size: .8rem; }
.stat b { font-size: 1.7rem; line-height: 1.2; color: var(--brand); font-variant-numeric: tabular-nums; }
.stat.attn b { color: #b0531b; }
.todo h2 { margin-bottom: 8px; }
.todo ul { list-style: none; margin: 0; padding: 0; }
.todo li { padding: 7px 0; border-bottom: 1px dashed var(--line); }
.todo li:last-child { border-bottom: 0; }
.todo li a { text-decoration: none; color: var(--text); }
.todo li a:hover { color: var(--brand); }
.todo li .status { min-width: 34px; text-align: center; margin-right: 6px; }
.todo li.bad { color: var(--danger); }
h2.sec { margin: 18px 0 10px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-bottom: 6px; }
.tile { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text);
  transition: border-color .15s, box-shadow .15s; }
.tile:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(15, 118, 110, .12); }
.tile-icon { flex-shrink: 0; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); font-size: 1.3rem; }
.tile-body { display: flex; flex-direction: column; min-width: 0; }
.tile-body small { color: var(--muted); font-size: .8rem; }
.tile-count { position: absolute; top: 8px; right: 10px; min-width: 22px; padding: 1px 7px; border-radius: 99px;
  background: var(--bg); font-size: .75rem; font-weight: 700; text-align: center; }
.tile-count.alert { background: #fdeee4; color: #b0531b; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; margin-top: 18px; }
.dash-grid .card { margin: 0; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 6px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.bar-stack { width: 100%; max-width: 40px; min-height: 2px; display: flex; flex-direction: column; border-radius: 6px 6px 2px 2px;
  overflow: hidden; background: var(--bg); }
.bar b { font-size: .8rem; }
.bar small { color: var(--muted); font-size: .72rem; }
.k-NK { background: #3aa76d; } .k-XK { background: #e08a4f; } .k-CK { background: #5b8ad8; }
.bar-stack span { display: block; min-height: 3px; }
.legend { font-size: .75rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 3px 0 8px; vertical-align: -1px; }
@media (max-width: 760px) {
  .stat-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat b { font-size: 1.35rem; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px; }
  .tile-body small { display: none; }
  .dash-grid { grid-template-columns: 1fr; }
  .bars { height: 130px; gap: 4px; }
}
.dash-grid td:first-child, .dash-grid .badge { white-space: nowrap; }
