:root {
  --bg: #f4f6f8; --panel: #fff; --text: #17202a; --muted: #5f6b7a; --line: #e2e7ec; --soft: #eef2f5;
  --brand: #0f766e; --brand-soft: #e6f4f2; --brand-text: #fff;
  --ok: #15803d; --ok-soft: #e8f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --bad: #b91c1c; --bad-soft: #fdecec;
  --info: #1d4ed8; --info-soft: #e8efff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Bố cục */
.layout { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: #0f2a2a; color: #d4e4e2; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.brand img { width: 30px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: #c5d7d5; margin-bottom: 2px; }
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a.on { background: var(--brand); color: #fff; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7fa09c; padding: 14px 10px 6px; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .me { border-top: 1px solid rgba(255, 255, 255, .1); margin-top: 16px; padding: 12px 10px 0; font-size: 13px; }
.side .me a { color: #9fc3be; }
.main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: none; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head .grow { flex: 1; }

/* Thành phần */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
.stat { padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: 13px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.stat.bad .v { color: var(--bad); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--soft); color: var(--bad); }

input[type=text], input[type=number], input[type=password], input[type=search], input[type=date], select, textarea {
  border: 1px solid #cfd7df; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }
label.f { display: block; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=search] { max-width: 340px; }
.filters select { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; padding: 5px 12px; border-radius: 99px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f8fafb; font-size: 12.5px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f8fbfb; }
td input[type=number] { width: 90px; text-align: right; padding: 5px 8px; }
td select { padding: 5px 8px; min-width: 110px; }
.sku { white-space: nowrap; }
.sku { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13.5px; font-weight: 600; }
.pname { max-width: 420px; }
.pname .v { color: var(--muted); font-size: 13px; }
.clip { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-mute { background: var(--soft); color: var(--muted); }
.plus { color: var(--ok); font-weight: 600; }
.minus { color: var(--bad); font-weight: 600; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; font-size: 13px; color: var(--muted); }
.empty { text-align: center; padding: 34px 10px; color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); color: #1e3a8a; font-size: 14px; }
.notice.warn { background: var(--warn-soft); color: #7c2d12; }
.notice.bad { background: var(--bad-soft); color: #7f1d1d; }

/* Ô quét mã */
.scan { position: relative; }
.scan input { font-size: 17px; padding: 12px 14px 12px 44px; border: 2px solid var(--brand); }
.scan svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 20px; color: var(--brand); }
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 20; max-height: 340px; overflow-y: auto; }
.suggest div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--soft); }
.suggest div.on, .suggest div:hover { background: var(--brand-soft); }

/* Hộp thoại */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 99; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: up .2s; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

/* Đăng nhập */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0f2a2a, #0f766e); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin-bottom: 4px; }

/* Ô kệ */
.shelves { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shelf { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; cursor: pointer; }
.shelf:hover { border-color: var(--brand); }
.shelf .c { font-family: Consolas, monospace; font-weight: 700; font-size: 15px; }
.shelf.empty-s { background: #fafbfc; }
.shelf.default { border-style: dashed; }

/* Tem in */
.bc { display: block; width: 100%; }
.labels { display: flex; flex-wrap: wrap; gap: 6px; }
.label { background: #fff; border: 1px dashed #c8d0d8; display: flex; flex-direction: column; justify-content: center; overflow: hidden; padding: 1.2mm 2mm; color: #000; font-family: Arial, sans-serif; }
.label .t { font-size: 7.5pt; line-height: 1.15; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; flex: none; }
.label .t.v { font-weight: 700; }
.label .code { font-family: Consolas, monospace; font-weight: 700; text-align: center; letter-spacing: .5px; }
.label .bcw { flex: 1; min-height: 0; display: flex; }
.label .bcw svg { height: 100%; }
.label.loc .code { font-size: 22pt; }
#print-area { display: none; }

@media print {
  body { background: #fff; }
  #app, #toasts { display: none !important; }
  #print-area { display: block !important; }
  .label { border: 0; page-break-inside: avoid; }
  .labels.roll { display: block; }
  .labels.roll .label { page-break-after: always; margin: 0; }
  .labels.sheet { gap: 0; }
  .doc-print { font-family: Arial, sans-serif; font-size: 12px; color: #000; }
  .doc-print table th, .doc-print table td { border: 1px solid #555; padding: 4px 6px; }
  .doc-print th { position: static; background: #eee; color: #000; }
}

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) {
  .layout { display: block; }
  .side { position: fixed; inset: 0 30% 0 0; max-width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .layout.open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #0f2a2a; color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; }
  .main { padding: 16px 16px 60px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .stat .v { font-size: 22px; }
}

/* Biểu đồ */
.viz { width: 100%; overflow: hidden; }
.viz svg { display: block; }
.viz .grid { stroke: #e9edf1; stroke-width: 1; }
.viz .base { stroke: #b9c2cb; stroke-width: 1; }
.viz .ax { font-size: 11px; fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.viz-tip { position: fixed; z-index: 100; display: none; background: #fff; border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.12); border-radius: 8px; padding: 8px 10px; font-size: 13px; color: var(--text); pointer-events: none; line-height: 1.5; }
.hb { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 54px; gap: 8px; align-items: center; padding: 4px 0; }
.hb-l { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hb-t { background: #f1f4f7; border-radius: 4px; height: 14px; }
.hb-b { background: #2a78d6; height: 14px; border-radius: 0 4px 4px 0; }
.hb-v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
/* Nút camera trong ô quét */
.scan .cam-btn { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: var(--brand-soft); color: var(--brand); border-radius: 8px; padding: 6px 8px; cursor: pointer; display: flex; }
.scan input { padding-right: 52px !important; }
.cam-line { position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #ef4444; box-shadow: 0 0 8px #ef4444; }
