:root {
  --brand: #0b5cab;
  --brand-d: #084a8a;
  --brand-l: #e8f1fb;
  --ok: #16803c;
  --ok-l: #e7f6ec;
  --warn: #b25e00;
  --warn-l: #fff4e0;
  --err: #c62828;
  --err-l: #fdecec;
  --info: #0b6aa8;
  --info-l: #e6f3fb;
  --text: #1c2430;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f6f9;
  --card: #fff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.grow { flex: 1; }
.pre { white-space: pre-wrap; }
.break { word-break: break-all; }
.text-err { color: var(--err); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ── Nút ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600;
  cursor: pointer; background: #fff; color: var(--text); white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-d); }
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover:not(:disabled) { background: #11672f; }
.btn-danger { background: var(--err); color: #fff; }
.btn-ghost { border-color: var(--line); background: #fff; }
.btn-ghost:hover:not(:disabled) { background: #f2f4f7; }
.btn-ghost-light { border: 1px solid rgba(255,255,255,.5); color: #fff; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: .88rem; }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }
.btn-block { width: 100%; }
.icon-btn { border: 0; background: transparent; font-size: 1.2rem; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: inherit; position: relative; }
.icon-btn:hover { background: #f2f4f7; text-decoration: none; }
.file-btn { cursor: pointer; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form ── */
.input {
  width: 100%; padding: 9px 12px; border: 1px solid #cfd4dc; border-radius: 8px; font: inherit; background: #fff; color: inherit;
}
.input:focus { outline: 2px solid rgba(11, 92, 171, .25); border-color: var(--brand); }
.input-lg { padding: 12px 14px; font-size: 1.05rem; }
textarea.input { resize: vertical; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 5px; color: #344054; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; }
.inline { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
fieldset { border: 0; padding: 0; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; }

/* ── Bố cục ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card, .grid-2 + .grid-2 { margin-top: 16px; }
.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters .input { width: auto; min-width: 150px; flex: 1 1 150px; }
.filters .check { margin: 0; }

.shell { display: flex; min-height: 100vh; }
.side {
  width: 250px; background: #0f2744; color: #cfdbea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0;
}
.side .brand { color: #fff; padding: 16px 18px; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: #cfdbea; margin-bottom: 2px; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.active { background: var(--brand); color: #fff; }
.nav .ni { width: 22px; text-align: center; }
.nav .badge { margin-left: auto; background: #ef4444; color: #fff; border-radius: 10px; font-size: .75rem; padding: 1px 7px; font-weight: 700; }
.side-foot { padding: 14px 18px; font-size: .85rem; border-top: 1px solid rgba(255,255,255,.08); }
.side-overlay { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; text-decoration: none !important; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; }
.bell .dot { position: absolute; top: 0; right: 0; background: #ef4444; color: #fff; font-size: .68rem; border-radius: 10px; padding: 0 5px; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 8px; color: inherit; padding: 4px 8px; border-radius: 8px; text-decoration: none !important; }
.user-chip:hover { background: #f2f4f7; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }
.uc-text { display: flex; flex-direction: column; line-height: 1.2; }
.uc-text small { color: var(--muted); }
.content { padding: 22px; max-width: 1280px; width: 100%; }

/* ── Trang công khai ── */
.pub-head { background: linear-gradient(120deg, #0b5cab, #0f2744); color: #fff; display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; }
.pub-head .brand { color: #fff; }
.pub-main { padding: 0 16px 40px; min-height: calc(100vh - 120px); }
.pub-foot { text-align: center; padding: 18px; color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); background: #fff; }
.hero { text-align: center; max-width: 720px; margin: 0 auto; padding: 40px 0 24px; }
.hero h1 { font-size: 1.8rem; margin-bottom: 8px; }
.hero p { color: var(--muted); margin: 0 0 22px; }
.search-box { display: flex; gap: 8px; }
.search-box .input { flex: 1; text-transform: uppercase; }
.login-wrap { display: grid; place-items: center; padding: 40px 0; }
.login-card { width: 100%; max-width: 400px; }

/* ── Kết quả tra cứu ── */
.result { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border-top: 4px solid var(--brand); margin-bottom: 16px; }
.result-ok { border-top-color: var(--ok); }
.result-warn { border-top-color: #f59e0b; }
.result-err { border-top-color: var(--err); background: #fffafa; }
.result-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 10px; }
.result-msg { margin: 14px 0 0; padding-top: 12px; border-top: 1px dashed var(--line); }
.success-banner { background: var(--ok); color: #fff; font-weight: 700; font-size: 1.15rem; padding: 14px; border-radius: var(--radius); text-align: center; margin-bottom: 12px; }
.activate-card h3 { margin-top: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid #f0f2f5; align-items: center; }
.kv > div:last-child { border-bottom: 0; }
.kv > div > span { color: var(--muted); flex-shrink: 0; }
.kv > div > b { text-align: right; font-weight: 600; }

/* ── Nhãn / cảnh báo ── */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.pill-lg { font-size: .95rem; padding: 5px 14px; }
.pill-ok { background: var(--ok-l); color: var(--ok); }
.pill-warn { background: var(--warn-l); color: var(--warn); }
.pill-err { background: var(--err-l); color: var(--err); }
.pill-info { background: var(--info-l); color: var(--info); }
.pill-gray { background: #eef0f3; color: #475467; }
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.block { display: block; text-decoration: none; }
.alert-ok { background: var(--ok-l); color: #0d5c2b; border-color: #b7e2c4; }
.alert-warn { background: var(--warn-l); color: #7a4100; border-color: #f5d7a1; }
.alert-err { background: var(--err-l); color: #8e1c1c; border-color: #f4bcbc; }
.alert-info { background: var(--info-l); color: #084d7a; border-color: #b9dcf2; }

/* ── Thống kê ── */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; color: inherit; text-decoration: none !important; border-left: 4px solid var(--brand); }
a.stat:hover { box-shadow: 0 4px 12px rgba(16,24,40,.12); }
.stat-ok { border-left-color: var(--ok); }
.stat-err { border-left-color: var(--err); }
.stat-err .stat-value { color: var(--err); }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.bars { display: flex; align-items: flex-end; gap: 3px; padding-top: 18px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.bar { width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.bar span { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: .68rem; color: var(--muted); }
.bar-label { font-size: .62rem; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; max-width: 100%; }

/* ── Bảng ── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; color: #475467; background: #f9fafb; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid #f0f2f5; vertical-align: top; }
.table .num { text-align: right; }
.table-click tbody tr[data-id], .table-click tbody tr[data-sn] { cursor: pointer; }
.table-click tbody tr:hover { background: #f5f8fc; }
.row-muted { opacity: .55; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.pager .muted { margin-right: auto; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); position: absolute; left: -6px; top: 13px; }
.notif-list { list-style: none; padding: 0; margin: 0; }
.notif-list li a { display: block; padding: 12px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.notif-list li.unread a { background: var(--brand-l); }
.notif-list p { margin: 4px 0; }

/* ── Hộp thoại & toast ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px; overflow-y: auto; }
.scan-video { width: 100%; border-radius: 8px; background: #000; max-height: 60vh; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1f2937; color: #fff; padding: 12px 16px; border-radius: 8px; max-width: 360px; opacity: 0; transform: translateY(10px); transition: all .25s; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--err); }

/* ── Thưởng kích hoạt ── */
.reward-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.reward-card { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: inherit; text-decoration: none !important; transition: box-shadow .15s; }
.reward-card:hover { box-shadow: 0 6px 18px rgba(16,24,40,.12); }
.reward-card img { width: 100%; aspect-ratio: 12 / 5; object-fit: cover; background: #eef1f5; }
.reward-noimg { aspect-ratio: 12 / 5; display: grid; place-items: center; font-size: 3rem; background: var(--brand-l); }
.reward-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.reward-points { color: var(--ok); font-weight: 700; font-size: 1.1rem; }
.reward-earned { margin-top: 12px; padding: 10px 12px; background: var(--ok-l); color: #0d5c2b; border-radius: 8px; font-weight: 600; }
.banner-full { margin-bottom: 16px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #fff; }
.banner-full img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: #0f2744; }
.banner-preview { border: 2px dashed var(--line); border-radius: 8px; min-height: 140px; display: grid; place-items: center; margin-bottom: 10px; overflow: hidden; background: #fafbfc; }
.banner-preview img { width: 100%; max-height: 260px; object-fit: contain; display: block; }
.model-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }
.model-item { margin-bottom: 6px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 7px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: .9rem; }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.align-start { align-items: start; }
.field-label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 8px; color: #344054; }
.text-warn { color: var(--warn); }
.text-ok { color: var(--ok); }
.mt { margin-top: 16px; }
.stats-2 { grid-template-columns: 1fr 1fr; }
form.grid-2 { margin-bottom: 16px; }

/* ── Popup bắt buộc ── */
.modal-backdrop.forced { background: rgba(15, 23, 42, .7); z-index: 60; }
.modal-popup { max-width: 560px; overflow: hidden; }
.popup-head { background: var(--brand); color: #fff; padding: 12px 18px; font-weight: 700; }
.popup-head.popup-end { background: #475467; }
.popup-head.popup-warn { background: var(--err); }
.popup-banner { display: block; width: 100%; max-height: 260px; object-fit: contain; background: #0f2744; }
.popup-body { padding: 16px 18px; overflow-y: auto; }
.popup-body h2 { margin: 0 0 8px; font-size: 1.2rem; }
.popup-actions { padding: 0 18px 18px; }
.popup-table { max-height: 220px; overflow-y: auto; }

/* ── Chế độ chỉ xem ── */
.viewas-bar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: #fff4e0; color: #7a4100; border-bottom: 1px solid #f5d7a1; padding: 8px 20px; font-size: .92rem; position: sticky; top: 53px; z-index: 4; }

/* ── Báo cáo ── */
.card-title a { color: inherit; text-decoration: none; display: inline-flex; align-items: baseline; gap: 8px; }
.card-title a:hover { color: var(--brand); }
.card-title .more { font-size: .8rem; font-weight: 500; color: var(--brand); }
.more-link { display: block; margin-top: 8px; font-size: .88rem; }
.back { text-decoration: none !important; color: var(--muted); margin-right: 4px; }
.table tfoot th { background: #f3f5f8; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: #f5f8fc; }

/* ── Bán lẻ / bán buôn ── */
.serial-preview { margin: -6px 0 14px; padding: 8px 12px; border-radius: 8px; font-size: .92rem; }
.serial-preview.ok { background: var(--ok-l); color: #0d5c2b; }
.serial-preview.bad { background: var(--err-l); color: #8e1c1c; }
.ac-wrap { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(16,24,40,.15); max-height: 320px; overflow-y: auto; margin-top: 4px; }
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f0f2f5; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.ac-item:hover, .ac-item.active { background: var(--brand-l); }
.ac-item small { width: 100%; }
.buyer-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--brand); background: var(--brand-l); border-radius: 8px; margin-bottom: 12px; }
.row-bad { background: #fff7f7; }
.steps { padding-left: 20px; margin: 0 0 8px; }
.steps li { margin-bottom: 10px; }
details > summary { cursor: pointer; }

/* ── Thưởng theo model ── */
.model-points .model-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid #f3f4f6; }
.model-points .model-row.on { background: var(--ok-l); }
.model-points .pts { width: 110px; text-align: right; }
.card-sub { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.excel-card { border-left: 4px solid var(--ok); }
.kv > .kv-block { display: block; }
.kv > .kv-block > span { display: block; margin-bottom: 6px; }

/* ── Nhật ký đối soát / bộ lọc ── */
.audit-timeline li { padding-bottom: 12px; }
.audit-timeline .row { justify-content: space-between; }
.audit-timeline .ev-approved::before, .audit-timeline .ev-owner_accepted::before { background: var(--ok); }
.audit-timeline .ev-rejected::before, .audit-timeline .ev-owner_rejected::before { background: var(--err); }
.audit-timeline .ev-withdrawn::before { background: #98a2b3; }
.ev-note { background: #f6f7f9; border-radius: 6px; padding: 6px 10px; margin-top: 4px; font-style: italic; }
.dealer-filter { display: inline-flex; align-items: center; gap: 4px; position: relative; flex: 1 1 220px; }
.dealer-filter[hidden] { display: none; }
.dealer-filter .input { min-width: 200px; }

.awaiting-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.audit-timeline .ev-reminded::before { background: #f59e0b; }

/* ── Sale ── */
.no-export #exportBtn, .no-export #expBtn { display: none !important; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.assign-tree { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.assign-tree .c1 { margin-top: 6px; font-weight: 600; }
.assign-tree .c2list { margin-left: 26px; }
.assign-tree .c2list .check { margin-bottom: 4px; font-weight: 400; }
.assign-tree .inherited { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.portfolio-c1 td:first-child { font-weight: 600; }
.portfolio-c2 td:first-child { padding-left: 28px; }

/* ── Thông báo ── */
.notif-list li.important a { border-left: 4px solid var(--brand); }

/* ── Di động ── */
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .side-overlay.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .menu-btn { display: inline-block; }
  .uc-text { display: none; }
  .content { padding: 14px; }
  .topbar { padding: 8px 12px; }
}
@media (max-width: 560px) {
  .hero { padding-top: 24px; }
  .hero h1 { font-size: 1.4rem; }
  .search-box { flex-wrap: wrap; }
  .search-box .input { flex-basis: 100%; }
  .search-box .btn { flex: 1; }
  .kv > div { flex-direction: column; align-items: flex-start; gap: 2px; }
  .kv > div > b { text-align: left; }
  .page-head h1 { font-size: 1.2rem; }
}
