:root {
  --bg: #f2f4f7;
  --panel: #fff;
  --text: #1f2329;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1e6fff;
  --primary-soft: #e8f0ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --warn: #c2410c;
  --warn-soft: #fff4e5;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --topbar: #13203a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 13px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ───── Khung chung kiểu BigSeller ───── */
.topbar { display: flex; align-items: center; height: 48px; padding: 0 16px; background: var(--topbar); color: #fff; gap: 4px; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; margin-right: 20px; letter-spacing: .3px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand .logo-mark { width: 26px; height: 26px; flex-shrink: 0; }
.topnav { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: #cfd6e4; padding: 14px 12px; white-space: nowrap; }
.topnav a.on { color: #fff; box-shadow: inset 0 -3px 0 var(--primary); }
.topnav a.off { opacity: .45; cursor: default; }
.who { white-space: nowrap; color: #cfd6e4; display: flex; gap: 10px; align-items: center; }
.who b { color: #fff; font-weight: 600; }
.layout { display: flex; min-height: calc(100vh - 48px); }
.sidenav { width: 196px; background: var(--panel); border-right: 1px solid var(--line); padding: 12px 0; flex-shrink: 0; }
.sidenav h4 { margin: 10px 16px 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.sidenav a { display: block; padding: 8px 16px 8px 24px; color: var(--text); }
.sidenav a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; border-right: 3px solid var(--primary); }
.sidenav a.off { color: #b0b5bd; cursor: default; }
.content { flex: 1; min-width: 0; padding: 16px; }
.page-title { font-size: 16px; font-weight: 600; margin: 0 0 12px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; margin-bottom: 12px; }
.filters { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; align-items: center; }
.filters > label { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 4px; padding: 3px 10px; cursor: pointer; }
.chip.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.searchbox { display: flex; gap: 6px; flex-wrap: wrap; }
.searchbox input[type=text] { flex: 1; min-width: 200px; }

input[type=text], input[type=number], input[type=password], input[type=date], input[type=email], input:not([type]), select, textarea {
  border: 1px solid #d0d5dd; border-radius: 4px; padding: 5px 8px; background: #fff; min-height: 30px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.btn { border: 1px solid #d0d5dd; background: #fff; border-radius: 4px; padding: 5px 12px; cursor: pointer; min-height: 30px; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f3c2c4; }
/* nút "Ẩn" màu xanh lá như BigSeller */
.btn.ok { background: #2fa35d; border-color: #2fa35d; color: #fff; }
.btn.ok:hover { filter: brightness(1.08); color: #fff; }
.btn.ok:disabled, .btn.primary:disabled { opacity: .55; }
.btn.small { padding: 2px 8px; min-height: 24px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0 4px; }
.link.danger { color: var(--danger); }

.toolbar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 10px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--text); white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.tabs .count { color: var(--muted); margin-left: 3px; }
.tabs a.on .count { color: var(--primary); }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
.grid th { background: #f7f8fa; font-weight: 600; text-align: left; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; color: #475467; }
.grid th.sortable { cursor: pointer; }
.grid td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tr:hover td { background: #fafbff; }
.grid .num { text-align: right; white-space: nowrap; }
.grid .chk { width: 32px; }
.prod { display: flex; gap: 8px; min-width: 220px; }
.thumb { width: 40px; height: 40px; border-radius: 4px; background: #eef1f5 center/cover no-repeat; flex-shrink: 0; display: grid; place-items: center; color: #98a2b3; font-size: 11px; }
.sub { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 32px; }

.tag { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 12px; line-height: 20px; background: #f2f4f7; color: #475467; white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--danger-soft); color: var(--danger); }
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.price-old { text-decoration: line-through; color: var(--muted); font-size: 12px; }

.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 10px; flex-wrap: wrap; }

/* ───── Hộp thoại ───── */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 20; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 640px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 1100px; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 15px; display: flex; justify-content: space-between; }
.modal .body { padding: 16px 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 14px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; color: var(--muted); margin-bottom: 3px; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea { width: 100%; }
.field .err { color: var(--danger); font-size: 12px; margin-top: 2px; }
.alert { padding: 8px 12px; border-radius: 4px; margin-bottom: 10px; }
.alert.bad { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--primary-soft); color: #1d4ed8; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.picker-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; margin-top: 8px; }
.picker-list .opt { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.picker-list .opt:hover, .picker-list .opt.on { background: var(--primary-soft); }
.stats { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.stats div { padding: 6px 12px; border-radius: 4px; background: #f7f8fa; }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }

#toast { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
#toast div { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 360px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
#toast div.bad { background: var(--danger); }

.login { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login .field { margin-top: 12px; }
.login .btn { width: 100%; margin-top: 16px; }

.narrow-only { display: none; }
@media (max-width: 760px) {
  .sidenav { display: none; }
  .narrow-only { display: flex; }
  .content { padding: 12px 16px; }
  .filters { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .brand { margin-right: 8px; }
  .brand span { display: none; } /* điện thoại: chỉ để logo, nhường chỗ cho menu */
  .who span { display: none; }
  .who #change-pw { display: none; } /* đổi mật khẩu làm trên máy tính */
}

/* In: chỉ in nội dung hộp thoại in */
@media print {
  body { background: #fff; }
  #app, #toast { display: none !important; }
  .overlay { position: static; background: none; padding: 0; overflow: visible; }
  .modal { box-shadow: none; max-width: none; }
  .modal header, .modal footer { display: none; }
  .modal .body { padding: 0; }
}
.modal h4 { margin: 14px 0 6px; }

/* Menu thả xuống (Nhập & Xuất, Thao tác hàng loạt) */
.dropdown { position: relative; display: inline-block; }
.dropdown .menu { display: none; position: absolute; top: 100%; left: 0; margin-top: 4px; min-width: 230px; background: #fff;
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.12); z-index: 10; padding: 4px 0; }
.toolbar .group:last-child .dropdown .menu { left: auto; right: 0; }
.dropdown .menu.open { display: block; }
.dropdown .menu button { display: block; width: 100%; text-align: left; padding: 8px 14px; border: 0; background: none; cursor: pointer; }
.dropdown .menu button:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.dropdown .menu button:disabled { color: #b0b5bd; cursor: not-allowed; }

/* Bảng sản phẩm online: gộp phân loại theo sản phẩm */
.listing-grid tr.grp-start td { border-top: 2px solid #d9dee7; }
.listing-grid td[rowspan] { background: #fff; }
.listing-grid tr:hover td[rowspan] { background: #fff; }

/* Hiệu ứng đang tải: thanh chạy trên cùng, nội dung mờ + vòng xoay (app.js · setLoading) */
#loadbar { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--primary); z-index: 60; opacity: 0; pointer-events: none;
  transition: width .25s ease, opacity .3s ease .1s; }
body.is-loading #loadbar { opacity: 1; width: 85%; transition: width 1.6s cubic-bezier(.1,.7,.3,1), opacity .1s; }
.content { position: relative; }
.content > * { transition: opacity .2s ease; }
body.is-loading .content > * { opacity: .45; }
body.is-loading .content, body.is-loading .sidenav { pointer-events: none; }
body.is-loading .content::after { content: ''; position: absolute; top: 90px; left: 50%; width: 30px; height: 30px; margin-left: -15px; z-index: 5;
  border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: wms-spin .7s linear infinite; }
@keyframes wms-spin { to { transform: rotate(360deg); } }

/* Trang đăng nhập: bên trái thương hiệu (phong cách quản lý kho), bên phải ô đăng nhập (app.js · authShell) */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, 46%) 1fr; background: var(--bg); }
.auth-brand { position: relative; overflow: hidden; color: #e6ecf7; padding: 40px 48px; display: flex; flex-direction: column; gap: 32px;
  background: linear-gradient(160deg, #0f1b33 0%, #15294f 55%, #0f1b33 100%); }
/* vân lưới mờ gợi sàn kho / kệ hàng */
.auth-brand::before { content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 36px 36px; -webkit-mask-image: linear-gradient(180deg, transparent, #000 25%, #000 75%, transparent); mask-image: linear-gradient(180deg, transparent, #000 25%, #000 75%, transparent); }
.auth-brand > * { position: relative; }
.auth-logo { display: flex; align-items: center; gap: 12px; }
.auth-logo .logo-mark { width: 44px; height: 44px; flex-shrink: 0; box-shadow: 0 6px 18px rgba(30,111,255,.35); border-radius: 10px; }
.auth-logo b { font-size: 20px; letter-spacing: .6px; color: #fff; }
.auth-logo span { font-size: 20px; font-weight: 300; color: #9db8ff; letter-spacing: .6px; }
.auth-logo small { display: block; font-size: 12px; color: #8a9bb8; letter-spacing: .5px; margin-top: 1px; }
.auth-pitch { margin: auto 0; max-width: 460px; }
.auth-pitch h2 { font-size: 30px; line-height: 1.25; margin: 0 0 12px; color: #fff; font-weight: 700; }
.auth-pitch p { color: #a9b6cc; margin: 0 0 28px; font-size: 15px; line-height: 1.6; }
.auth-feats { list-style: none; padding: 0; margin: 0; display: grid; gap: 18px; }
.auth-feats li { display: flex; gap: 14px; align-items: flex-start; }
.auth-feats svg { width: 36px; height: 36px; padding: 8px; border-radius: 9px; background: rgba(30,111,255,.16); color: #82abff; flex-shrink: 0; border: 1px solid rgba(130,171,255,.18); }
.auth-feats b { display: block; color: #fff; font-weight: 600; margin-bottom: 2px; }
.auth-feats span { color: #a3b1c8; font-size: 13.5px; line-height: 1.5; }
.auth-foot { font-size: 12px; color: #7d8ba3; display: flex; gap: 16px; flex-wrap: wrap; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth .login { margin: 0; width: 100%; max-width: 400px; border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(15,27,51,.08); border-radius: 12px; padding: 32px; }
.auth .login h1 { font-size: 22px; margin-bottom: 6px; }
.auth .login .sub { line-height: 1.5; }
.auth .login .field { margin-top: 16px; }
.auth .login .field label { color: var(--text); font-weight: 500; margin-bottom: 6px; }
.auth .login input { padding: 9px 12px; font-size: 15px; border-radius: 6px; }
.auth .login .btn { height: 42px; font-size: 15px; border-radius: 6px; margin-top: 20px; }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-brand { padding: 18px 16px; gap: 0; }
  .auth-pitch, .auth-foot { display: none; }
  .auth-logo .logo-mark { width: 38px; height: 38px; }
  .auth-main { align-items: flex-start; padding: 20px 16px 32px; }
  .auth .login { padding: 24px 20px; box-shadow: none; }
}

/* Ảnh bìa: xe nâng chở hàng vào kho (app.js · HERO_SVG) */
.auth-hero { max-width: 460px; cursor: pointer; }
.auth-hero svg { display: block; width: 100%; height: auto; max-height: 200px; }
.hz-truck { animation: hz-drive 4.5s ease-in-out infinite; transition: transform .9s cubic-bezier(.3,.7,.2,1); }
.hz-lines { animation: hz-fade 1.2s ease-in-out infinite; }
.hz-beacon { animation: hz-blink 1.4s steps(2, end) infinite; }
.hz-door { transition: transform .6s ease; }
@keyframes hz-drive { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(14px); } }
@keyframes hz-fade { 0%, 100% { opacity: .15; } 50% { opacity: .7; } }
@keyframes hz-blink { 50% { opacity: .25; } }
/* rê chuột vào ảnh: xe chạy sâu vào cửa kho, cửa kéo lên */
.auth-hero:hover .hz-truck { animation: none; transform: translateX(36px); }
.auth-hero:hover .hz-door { transform: translateY(-8px); }

/* Hiệu ứng rê / bấm: logo, tiêu đề, dòng tính năng, nút */
.auth-logo .logo-mark { transition: transform .25s ease, box-shadow .25s ease; cursor: pointer; }
.auth-logo:hover .logo-mark { transform: rotate(-8deg) scale(1.08); box-shadow: 0 8px 22px rgba(30,111,255,.55); }
.auth-logo:active .logo-mark { transform: rotate(-8deg) scale(.96); }
.auth-pitch h2 span { background-image: linear-gradient(90deg, #4f8cff, #9db8ff); background-size: 0 3px; background-repeat: no-repeat; background-position: 0 100%;
  padding-bottom: 4px; transition: background-size .45s ease, color .3s ease; cursor: default; }
.auth-pitch h2:hover span { background-size: 100% 3px; color: #dce7ff; }
.auth-feats li { padding: 6px 8px; margin: -6px -8px; border-radius: 10px; transition: background .2s ease, transform .2s ease; cursor: default; }
.auth-feats li:hover { background: rgba(255,255,255,.05); transform: translateX(4px); }
.auth-feats li:active { transform: translateX(4px) scale(.98); }
.auth-feats svg { transition: transform .25s ease, background .25s ease, color .25s ease; }
.auth-feats li:hover svg { transform: scale(1.12) rotate(-6deg); background: rgba(30,111,255,.38); color: #fff; }
.auth .login .btn.primary { transition: transform .15s ease, box-shadow .15s ease, filter .15s ease; }
.auth .login .btn.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(30,111,255,.35); filter: brightness(1.05); }
.auth .login .btn.primary:active:not(:disabled) { transform: translateY(1px) scale(.99); box-shadow: 0 2px 6px rgba(30,111,255,.3); }
.auth .login .link { transition: color .15s ease; }
.auth .login .link:hover { text-decoration: underline; }
.auth .login input { transition: border-color .15s ease, box-shadow .15s ease; }
.auth .login input:focus { box-shadow: 0 0 0 3px var(--primary-soft); outline: none; }
/* màn hình thấp: rút gọn mô tả tính năng để vừa một trang */
@media (min-width: 861px) and (max-height: 860px) { .auth-feats span { display: none; } .auth-feats { gap: 10px; } .auth-hero svg { max-height: 170px; } }
@media (max-width: 860px) { .auth-hero { margin: 12px auto 0; max-width: 360px; } .auth-hero svg { max-height: 130px; } }
@media (prefers-reduced-motion: reduce) { .hz-truck, .hz-lines, .hz-beacon { animation: none; } }

/* Nút công cụ quét trên điện thoại (orders.js · mobileToolsHtml) */
.mobile-tools { margin: 0 0 12px; }
.mobile-tools .btn { width: 100%; justify-content: center; align-items: center; gap: 8px; min-height: 46px; font-size: 16px; display: flex; }
.mobile-tools svg { width: 22px; height: 22px; }
.mobile-tools { flex-direction: column; gap: 8px; }
/* Quét đơn trên điện thoại: danh sách thẻ thay cho bảng (orders.js · renderScan) */
.scan-list { padding: 12px; }
.scan-item { border-top: 1px solid var(--line); padding: 8px 0; }
.scan-item:first-of-type { margin-top: 8px; }
