/* ============================================================
   Tồn kho NCC — Design System (GVN AI Hub tokens)
   Vanilla CSS, no build. Light/Dark via [data-theme] on <html>.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --elevated: #F3F4F6;
  --border: #E4E7EC;
  --border-strong: #D1D5DB;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;          /* ≥4.5:1 on white (was #98A2B3 ~2.6:1) */
  --primary: #0EA5E9;
  --primary-light: #E0F2FE;
  --primary-hover: #0284C7;
  --primary-contrast: #FFFFFF;

  --success: #15803D;        /* darker fg for ≥4.5:1 text-on-tint */
  --success-bg: #DCFCE7;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --danger: #B91C1C;
  --danger-bg: #FEE2E2;
  --info: #2563EB;
  --info-bg: #DBEAFE;
  --neutral-bg: #F1F5F9;

  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow-md: 0 4px 8px -2px rgba(16,24,40,.10), 0 2px 4px -2px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 16px -4px rgba(16,24,40,.08), 0 4px 6px -2px rgba(16,24,40,.03);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --sb-thumb: rgba(152,162,179,.4);
  --sb-thumb-hover: rgba(152,162,179,.65);

  --header-h: 60px;
  --sidebar-w: 232px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

html[data-theme="dark"] {
  --bg: #0F172A;
  --surface: #1E293B;
  --elevated: #334155;
  --border: rgba(255,255,255,.10);
  --border-strong: rgba(255,255,255,.20);
  --text: #F8FAFC;
  --text-2: #CBD5E1;
  --muted: #94A3B8;
  --primary: #38BDF8;
  --primary-light: rgba(14,165,233,.15);
  --primary-hover: #7DD3FC;
  --primary-contrast: #04121E;

  --success: #4ADE80;
  --success-bg: rgba(34,197,94,.15);
  --warn: #FBBF24;
  --warn-bg: rgba(217,119,6,.18);
  --danger: #F87171;
  --danger-bg: rgba(220,38,38,.18);
  --info: #60A5FA;
  --info-bg: rgba(37,99,235,.18);
  --neutral-bg: rgba(148,163,184,.14);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.5);
  --sb-thumb: rgba(100,116,139,.4);
  --sb-thumb-hover: rgba(100,116,139,.65);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--sb-thumb); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--sb-thumb-hover); }
::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* safety net: any inline <svg><use/></svg> gets a sane size unless a component overrides it */
.app svg, .sheet svg, .toast svg { width: 16px; height: 16px; }

/* ---------- App shell ---------- */
.app { display: none; min-height: 100vh; }
.app.is-visible { display: block; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.topbar .brand .logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff; font-weight: 800; font-size: 15px; flex: none;
}
.topbar .brand small { color: var(--muted); font-weight: 500; }
.topbar .spacer { flex: 1; }
.topbar .meta-fresh { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
  display: grid; place-items: center; transition: background .18s, color .18s, border-color .18s;
}
.icon-btn:hover { background: var(--elevated); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.user-chip { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); }
.user-chip .av { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-chip .uname { font-weight: 600; font-size: 13px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout body */
.shell { display: flex; align-items: stretch; }
.sidebar {
  width: var(--sidebar-w); flex: none;
  border-right: 1px solid var(--border); background: var(--surface);
  padding: 14px 10px; position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h)); overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 10px; border: 0; background: transparent;
  color: var(--text-2); font-weight: 550; font-size: 14px; text-align: left; margin-bottom: 2px;
  transition: background .16s, color .16s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--elevated); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary-hover); font-weight: 650; }
html[data-theme="dark"] .nav-item.active { color: var(--primary); }
.nav-sep { height: 1px; background: var(--border); margin: 10px 8px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 12px 4px; font-weight: 700; }

.content { flex: 1; min-width: 0; padding: 20px; max-width: 1600px; margin: 0 auto; width: 100%; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Cards / KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); transition: box-shadow .2s, transform .2s;
  display: flex; flex-direction: column; gap: 8px;
}
.kpi:hover { box-shadow: var(--shadow-md); }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi .kpi-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-light); color: var(--primary); flex: none; }
.kpi .kpi-ic svg { width: 18px; height: 18px; }
.kpi .kpi-val { font-size: 24px; font-weight: 750; letter-spacing: -.02em; }
.kpi .kpi-foot { font-size: 12px; color: var(--muted); }
.kpi.ic-amber .kpi-ic { background: var(--warn-bg); color: var(--warn); }
.kpi.ic-green .kpi-ic { background: var(--success-bg); color: var(--success); }
.kpi.ic-red .kpi-ic { background: var(--danger-bg); color: var(--danger); }

/* ---------- Toolbar / search / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box svg.lead { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search-box input {
  width: 100%; height: 42px; padding: 0 38px 0 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px;
  transition: border-color .16s, box-shadow .16s;
}
.search-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.search-box .kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; font-family: var(--mono); }
.search-box .clear { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; background: var(--elevated); color: var(--text-2); width: 24px; height: 24px; border-radius: 6px; display: none; place-items: center; }
.search-box.has-value .clear { display: grid; }
.search-box.has-value .kbd { display: none; }

.btn {
  height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 13.5px;
  display: inline-flex; align-items: center; gap: 8px; transition: background .16s, color .16s, border-color .16s;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--elevated); color: var(--text); }
.btn.primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.sm { height: 34px; padding: 0 10px; font-size: 12.5px; }
.btn.active { background: var(--primary-light); border-color: var(--primary); color: var(--primary-hover); }

.select {
  height: 42px; padding: 0 34px 0 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2398A2B3' stroke-width='2' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 10px center;
  color: var(--text); font-size: 13.5px; -webkit-appearance: none; appearance: none; max-width: 200px;
}
.select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* filter chips row */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 6px 0 12px;
  border-radius: var(--radius-pill); border: 1px solid var(--primary); background: var(--primary-light);
  color: var(--primary-hover); font-size: 12.5px; font-weight: 600;
}
html[data-theme="dark"] .chip { color: var(--primary); }
.chip button { border: 0; background: transparent; color: inherit; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; }
.chip button:hover { background: rgba(0,0,0,.08); }

/* segmented control (region) */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; color: var(--text-2); height: 42px; padding: 0 14px; font-weight: 600; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--primary-light); color: var(--primary-hover); }
html[data-theme="dark"] .seg button.active { color: var(--primary); }

/* ---------- Table ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-sm); }
.table-scroll { overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 680px; table-layout: fixed; }
table.grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--elevated); color: var(--text-2); font-weight: 650; text-align: left;
  padding: 11px 12px; white-space: nowrap; border-bottom: 1px solid var(--border); user-select: none;
}
table.grid thead th.sortable { cursor: pointer; }
table.grid thead th.sortable:hover { color: var(--text); }
table.grid thead th .th-in { display: inline-flex; align-items: center; gap: 5px; }
table.grid thead th.r .th-in { flex-direction: row-reverse; }
table.grid thead th svg { width: 13px; height: 13px; opacity: .5; }
table.grid thead th.sorted svg { opacity: 1; color: var(--primary); }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tbody tr { transition: background .12s; }
table.grid tbody tr:hover { background: var(--elevated); }
table.grid td.r, table.grid th.r { text-align: right; }
table.grid td.c, table.grid th.c { text-align: center; }
table.grid td.name { max-width: 340px; }
table.grid td.name .pname { font-weight: 550; color: var(--text); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
table.grid td.sku { font-family: var(--mono); font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.grid td, table.grid th { overflow: hidden; }
table.grid td.qty { font-variant-numeric: tabular-nums; font-weight: 600; }
table.grid td.qty.zero { color: var(--muted); font-weight: 500; }
table.grid td.price { font-variant-numeric: tabular-nums; color: var(--text-2); }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.grid tbody tr:hover .sticky-col { background: var(--elevated); }
table.grid thead th.sticky-col { z-index: 3; background: var(--elevated); }

.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); flex-wrap: wrap; background: var(--surface); }
.table-foot .count { color: var(--muted); font-size: 12.5px; }
.pager { display: flex; align-items: center; gap: 6px; }
.pager button { min-width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-weight: 600; }
.pager button:hover:not(:disabled) { background: var(--elevated); color: var(--text); }
.pager button:disabled { opacity: .45; cursor: not-allowed; }
.pager button.active { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--radius-pill); font-size: 11.5px; font-weight: 650; white-space: nowrap;
  background: var(--neutral-bg); color: var(--text-2);
}
.badge svg { width: 13px; height: 13px; flex: none; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.pass { background: var(--success-bg); color: var(--success); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.fail, .badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.auto { background: var(--info-bg); color: var(--info); }
.badge.static { background: var(--neutral-bg); color: var(--muted); }
.badge.stale { background: var(--warn-bg); color: var(--warn); }
.badge.instock { background: var(--success-bg); color: var(--success); }
.badge.out { background: var(--danger-bg); color: var(--danger); }

/* ---------- Source-health (sync) cards ---------- */
.src-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.src-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 15px; box-shadow: var(--shadow-sm); transition: box-shadow .2s, border-color .2s; }
.src-card:hover { box-shadow: var(--shadow-md); }
.src-card.is-warn { border-color: var(--warn); }
.src-card.is-stale { border-left: 3px solid var(--warn); }
.src-card .sc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.src-card .sc-title { font-weight: 700; font-size: 14.5px; }
.src-card .sc-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.src-card .sc-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.src-card .sc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.src-card .sc-stat { background: var(--elevated); border-radius: var(--radius-sm); padding: 8px; text-align: center; }
.src-card .sc-stat .v { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.src-card .sc-stat .l { color: var(--muted); font-size: 11px; margin-top: 1px; }
.src-card .sc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.src-card .finding { display: flex; align-items: center; gap: 6px; margin-top: 8px; padding: 7px 9px; border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn); font-size: 12px; font-weight: 550; }

/* ---------- Empty / loading ---------- */
.empty { text-align: center; padding: 54px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 10px; }
.empty h3 { color: var(--text-2); font-size: 15px; margin-bottom: 4px; }
.empty p { font-size: 13px; }
.skeleton { position: relative; overflow: hidden; background: var(--elevated); border-radius: 6px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.25), transparent); animation: shimmer 1.3s infinite; }
html[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------- Login gate ---------- */
#loadingSection { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loginSection { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 600px at 50% -10%, var(--primary-light), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 30px 28px; }
.login-card .logo-lg { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-hover)); color: #fff; font-weight: 800; font-size: 24px; margin-bottom: 16px; }
.login-card h1 { font-size: 22px; }
.login-card .lsub { color: var(--muted); font-size: 13.5px; margin: 4px 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field input { width: 100%; height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; }
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.login-card .submit { width: 100%; height: 46px; border-radius: 10px; border: 0; background: var(--primary); color: var(--primary-contrast); font-weight: 700; font-size: 15px; margin-top: 6px; transition: background .18s; }
.login-card .submit:hover { background: var(--primary-hover); }
.login-card .submit:disabled { opacity: .7; cursor: progress; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; font-weight: 550; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 20px; }

/* toast */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 550; box-shadow: var(--shadow-lg); animation: fade .2s ease; }

/* ---------- Offline banner ---------- */
.offline-banner { display: flex; align-items: center; gap: 9px; padding: 9px 16px; background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 600; border-bottom: 1px solid var(--border); }
.offline-banner svg { width: 17px; height: 17px; flex: none; }

/* ---------- mobile sort select (visible only in card mode) ---------- */
.sort-select { display: none; }
@media (max-width: 899px) { .sort-select { display: inline-block; flex: 1; min-width: 130px; } }

/* ---------- Topbar nav tabs ---------- */
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.topnav .tab {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px;
  border: 0; background: transparent; color: var(--text-2); font-weight: 600; font-size: 14px; border-radius: 9px;
  transition: background .16s, color .16s;
}
.topnav .tab svg { width: 17px; height: 17px; }
.topnav .tab:hover { background: var(--elevated); color: var(--text); }
.topnav .tab.active { background: var(--primary-light); color: var(--primary-hover); }
html[data-theme="dark"] .topnav .tab.active { color: var(--primary); }

/* ---------- Mobile nav ---------- */
.mobile-tabbar { display: none; }
.hamburger { display: none; }
.backdrop { display: none; }
.backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 55; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1024px) {
  .content { padding: 16px; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

@media (max-width: 899px) {
  body { font-size: 13.5px; }
  .topnav { display: none; }               /* nav moves to bottom tabbar */
  .topbar .meta-fresh { display: none; }
  .content { padding: 14px 12px 76px; }     /* room for bottom tabbar */
  .page-head h1 { font-size: 18px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  /* ≥44px touch targets */
  .search-box input, .btn, .select, .seg button, .pager button { min-height: 44px; }
  .icon-btn, #logoutBtn { min-width: 44px; min-height: 44px; }
  .seg button { min-width: 48px; }
  .kpi .kpi-val { font-size: 20px; }
  .toolbar { gap: 8px; }
  .search-box { min-width: 100%; order: -1; }
  .select { max-width: none; flex: 1; }
  .src-grid { grid-template-columns: 1fr; }
  .user-chip .uname { display: none; }
  /* SKU table becomes cards on phones */
  .table-scroll.as-cards table.grid { min-width: 0; }
  .table-scroll.as-cards thead { display: none; }
  .table-scroll.as-cards tbody tr { display: block; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 4px; background: var(--surface); box-shadow: var(--shadow-sm); }
  .table-scroll.as-cards tbody tr:hover { background: var(--surface); }
  .table-scroll.as-cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 6px 12px; text-align: right; }
  .table-scroll.as-cards td::before { content: attr(data-label); color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; flex: none; }
  .table-scroll.as-cards td.name { max-width: none; }
  .table-scroll.as-cards td.name .pname { -webkit-line-clamp: 3; text-align: right; }
  .table-scroll.as-cards td.sticky-col { position: static; }
  .table-scroll.as-cards td.hide-card { display: none; }
  /* bottom tab bar */
  .mobile-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 10px rgba(16,24,40,.06);
  }
  .mobile-tabbar button { flex: 1; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px; font-size: 11px; font-weight: 600; }
  .mobile-tabbar button svg { width: 20px; height: 20px; }
  .mobile-tabbar button.active { color: var(--primary); }
}

@media (max-width: 560px) {
  #syncBadge { display: none; }   /* covered by KPI "Nguồn cảnh báo" + Nguồn tab */
  .topbar { gap: 8px; padding: 0 12px; }
  .table-scroll.as-cards td.sku { word-break: break-all; }
}
@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 12px 10px 76px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ============================================================
   Search layout: filter rail + results
   ============================================================ */
.search-layout { display: grid; grid-template-columns: 264px 1fr; gap: 16px; align-items: start; }
@media (min-width: 1200px) { #filterBtn { display: none; } } /* rail persistent → no toggle needed */
.filter-panel { position: sticky; top: calc(var(--header-h) + 16px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.filter-panel .fp-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 13.5px; }
.filter-panel .fp-body { max-height: calc(100vh - var(--header-h) - 120px); overflow-y: auto; padding: 4px 0 8px; }
.filter-sheet-actions { display: none; }

.facet { border-bottom: 1px solid var(--border); }
.facet:last-child { border-bottom: 0; }
.facet-head { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; background: transparent; color: var(--text); font-weight: 650; font-size: 13px; padding: 11px 14px; }
.facet-head .cnt { color: var(--muted); font-weight: 600; font-size: 12px; }
.facet-head svg { width: 15px; height: 15px; transition: transform .18s; color: var(--muted); }
.facet.collapsed .facet-head svg { transform: rotate(-90deg); }
.facet-body { padding: 0 10px 10px; }
.facet.collapsed .facet-body { display: none; }
.facet-search { width: 100%; height: 32px; padding: 0 10px; margin-bottom: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 12.5px; }
.facet-list { max-height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.facet-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 12.5px; transition: background .12s; }
.facet-opt:hover { background: var(--elevated); }
.facet-opt input { accent-color: var(--primary); width: 15px; height: 15px; flex: none; }
.facet-opt .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-opt .oc { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.facet-opt.dim { opacity: .4; }
.facet-toggles { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px 12px; }
.tgl { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; padding: 5px 4px; }
.tgl input { position: absolute; opacity: 0; }
.tgl .box { width: 34px; height: 20px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .18s; flex: none; }
.tgl .box::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: var(--shadow-sm); }
.tgl input:checked + .box { background: var(--primary); }
.tgl input:checked + .box::after { transform: translateX(14px); }
.tgl input:focus-visible + .box { outline: 2px solid var(--primary); outline-offset: 2px; } /* keyboard focus ring on the visible switch */

/* KPI ribbon = slim clickable tiles */
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--primary); transform: translateY(-1px); }

/* ============================================================
   Sync / source-health table
   ============================================================ */
.summary-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.summary-strip .cell { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; min-width: 110px; box-shadow: var(--shadow-sm); }
.summary-strip .cell .v { font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; }
.summary-strip .cell .l { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.summary-strip .cell.warn .v { color: var(--warn); }
.summary-strip .cell.ok .v { color: var(--success); }

table.grid td.src { font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.delta { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 6px; }
.delta.up { color: var(--success); background: var(--success-bg); }
.delta.down { color: var(--danger); background: var(--danger-bg); }
.delta.flat { color: var(--muted); background: var(--neutral-bg); }

/* PCRU fingerprint */
.fp { display: inline-flex; gap: 3px; }
.fp .g { width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; font-family: var(--mono); font-size: 11px; font-weight: 700; background: var(--success-bg); color: var(--success); }
.fp .g.off { background: var(--neutral-bg); color: var(--muted); text-decoration: line-through; }
.fp .g.lost { background: var(--warn-bg); color: var(--warn); box-shadow: 0 0 0 2px var(--warn) inset; }
.findings-list { display: flex; flex-direction: column; gap: 5px; margin-top: 8px; }
.finding-line { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 6px 9px; border-radius: 7px; background: var(--warn-bg); color: var(--warn); }
.finding-line svg { width: 9px; height: 9px; flex: none; }
.finding-line.high { background: var(--danger-bg); color: var(--danger); }
.expand-row td { background: var(--elevated); padding: 4px 14px 12px; }

/* ============================================================
   Bottom sheet / slide-over (filters + detail)
   ============================================================ */
.overlay-back { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 70; opacity: 0; pointer-events: none; transition: opacity .22s; }
.overlay-back.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 80; background: var(--surface); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transition: transform .26s cubic-bezier(.4,0,.2,1);
}
/* right slide-over (desktop detail) */
.sheet.right { top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw; border-left: 1px solid var(--border); transform: translateX(100%); }
.sheet.right.open { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.sheet-head h3 { font-size: 16px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.sheet-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; }

.detail-hero { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.detail-qty { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 14px 0; }
.detail-qty .q { background: var(--elevated); border-radius: 10px; padding: 12px 10px; text-align: center; }
.detail-qty .q .v { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.detail-qty .q .v.zero { color: var(--danger); }
.detail-qty .q .v.na { color: var(--muted); }
.detail-qty .q .l { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.kv { display: grid; grid-template-columns: 116px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text); word-break: break-word; }
.kv dd.mono { font-family: var(--mono); font-size: 12px; }

/* filter rail persistent only ≥1200; below that it is a bottom sheet (table gets full width) */
@media (max-width: 1199px) {
  .search-layout { grid-template-columns: 1fr; }
  .filter-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 80; border-radius: 18px 18px 0 0;
    max-height: 88vh; transform: translateY(100%); transition: transform .26s cubic-bezier(.4,0,.2,1);
  }
  .filter-panel.open { transform: none; }
  .filter-panel .fp-body { max-height: calc(88vh - 120px); }
  .filter-sheet-actions { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
  .filter-sheet-actions .btn { flex: 1; justify-content: center; }
}
/* detail: right slide-over ≥900, bottom sheet below */
@media (max-width: 899px) {
  .sheet.right { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-width: none; height: 90vh; border-left: 0; border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; transform: translateY(100%); }
  .sheet.right.open { transform: none; }
}

mark { background: var(--warn-bg); color: inherit; padding: 0 1px; border-radius: 3px; }
html[data-theme="dark"] mark { background: rgba(251,191,36,.25); }

/* responsive column hiding (table mode) */
@media (max-width: 1023px) { table.grid th.hide-1024, table.grid td.hide-1024 { display: none; } }
@media (max-width: 767px)  { table.grid th.hide-768,  table.grid td.hide-768  { display: none; } }
/* in phone card mode, re-show every field as a label:value row so cards are complete */
@media (max-width: 899px) {
  .table-scroll.as-cards td { overflow: visible; }
  .table-scroll.as-cards td.hide-768,
  .table-scroll.as-cards td.hide-1024 { display: flex; }
  .table-scroll.as-cards td.name { flex-direction: column; align-items: stretch; }
  .table-scroll.as-cards td.name::before { margin-bottom: 4px; }
  .table-scroll.as-cards td.name .pname { -webkit-line-clamp: 3; text-align: left; }
  .table-scroll.as-cards td.total { border-top: 1px dashed var(--border); margin-top: 2px; }
  .table-scroll.as-cards td.total .qty { font-size: 17px; }
}
