@font-face { font-family: "Poppins"; font-weight: 400; font-display: swap; src: url("fonts/poppins-400.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 500; font-display: swap; src: url("fonts/poppins-500.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 600; font-display: swap; src: url("fonts/poppins-600.woff2") format("woff2"); }

:root {
  --page: #e7ecf3;
  --shell: #eef2f8;
  --card: #f6f8fc;
  --card-solid: #ffffff;
  --line: #e1e7f0;
  --ink: #222436;
  --ink-2: #4a4d5e;
  --muted: #999b9f;
  --blue: #4d87f3;
  --blue-deep: #1032e0;
  --blue-soft: #afd4f9;
  --bar: #dfe5f8;
  --good: #17a34a;
  --good-bg: #e3f6e9;
  --bad: #e5484d;
  --bad-bg: #fde8e8;
  --warn: #c27c0e;
  --warn-bg: #fdf1dc;
  --radius: 16px;
  --font: "Poppins", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: inherit; }

/* ---------------------------------------------------------------- shell */
.shell {
  max-width: 1480px;
  margin: 24px auto;
  background: var(--shell);
  border-radius: 24px;
  padding: 20px 24px 24px 0;
  display: grid;
  grid-template-columns: 88px 1fr;
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 48px);
  box-shadow: 0 20px 60px -30px rgba(34, 36, 54, .25);
}
.brand { grid-column: 1; grid-row: 1; display: flex; justify-content: center; align-items: center; }
.logo {
  width: 48px; height: 48px; border-radius: 50%; background: var(--card-solid);
  display: grid; place-items: center; box-shadow: 0 2px 8px rgba(34,36,54,.06);
}
.topbar { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: 12px; padding-bottom: 18px; }
.topbar h1 { font-size: 20px; font-weight: 500; margin: 0; letter-spacing: -.01em; }
.topbar .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar .spacer { flex: 1; }
.circle-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card-solid);
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
  box-shadow: 0 2px 8px rgba(34,36,54,.05); transition: background .15s, color .15s;
}
.circle-btn:hover { background: #fff; color: var(--blue); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 16px; cursor: pointer; border: 3px solid #fff;
  position: relative;
}
.menu {
  position: absolute; right: 0; top: 56px; background: #fff; border-radius: 12px; padding: 6px; min-width: 150px;
  box-shadow: 0 12px 32px -8px rgba(34,36,54,.25); display: none; z-index: 30; color: var(--ink); font-weight: 400; font-size: 13px;
}
.menu.open { display: block; }
.menu button { width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--shell); }

.sync-pill {
  display: flex; align-items: center; gap: 10px; background: var(--card-solid); border-radius: 999px;
  padding: 6px 6px 6px 16px; box-shadow: 0 2px 8px rgba(34,36,54,.05);
}
.sync-pill .meta { font-size: 12px; color: var(--muted); line-height: 1.3; }
.sync-pill .meta b { color: var(--ink); font-weight: 500; }
.btn {
  border: 0; border-radius: 999px; padding: 9px 16px; cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { background: #9db9ef; cursor: progress; }
.btn-ghost { background: var(--card-solid); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--bad-bg); color: var(--bad); }
.btn-sm { padding: 6px 12px; font-size: 12px; }

.sidebar {
  grid-column: 1; grid-row: 2; display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 60px;
}
.sidebar .nav { display: flex; flex-direction: column; gap: 14px; }
.sidebar .bottom { margin-top: auto; }
.nav-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card-solid); cursor: pointer; color: var(--ink-2);
  display: grid; place-items: center; position: relative; transition: background .15s, color .15s;
}
.nav-btn:hover { color: var(--blue); }
.nav-btn.active { background: var(--blue); color: #fff; box-shadow: 0 8px 18px -6px rgba(77,135,243,.7); }
.nav-btn .tip {
  position: absolute; left: 54px; background: var(--ink); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px;
  white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 20;
}
.nav-btn:hover .tip { opacity: 1; }

main { grid-column: 2; grid-row: 2; min-width: 0; }
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- cards */
.card {
  background: var(--card); border: 1px solid #fff; border-radius: var(--radius); padding: 16px 18px; position: relative;
  min-width: 0; box-shadow: 0 1px 0 rgba(34,36,54,.02);
}
.card-head { display: flex; align-items: center; gap: 10px; min-height: 28px; }
.card-title { font-size: 13px; font-weight: 500; color: var(--ink); }
.card-head .spacer { flex: 1; }
.arrow-btn {
  width: 28px; height: 28px; border-radius: 8px; background: #fff; border: 0; display: grid; place-items: center;
  cursor: pointer; color: var(--ink); flex-shrink: 0;
}
.arrow-btn:hover { color: var(--blue); }
.select {
  appearance: none; border: 1px solid var(--line); background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23222436' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  border-radius: 8px; padding: 5px 28px 5px 10px; font-size: 12px; cursor: pointer;
}
.muted { color: var(--muted); }
.big { font-size: 22px; font-weight: 500; letter-spacing: -.01em; }
.huge { font-size: 26px; font-weight: 500; letter-spacing: -.02em; }
.delta { font-size: 11px; font-weight: 500; border-radius: 6px; padding: 2px 6px; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--bad); background: var(--bad-bg); }
.delta.flat { color: var(--muted); background: #eef0f4; }

.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 14px; }
.row2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); margin-bottom: 14px; }
.row3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); margin-bottom: 14px; }
.row3 .stack { display: grid; grid-template-rows: 1fr 1fr; gap: 14px; }
.row4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.kpi { padding: 14px 16px 12px; }
.kpi .body { display: flex; align-items: flex-end; gap: 8px; margin-top: 18px; }
.kpi .val { flex: 1; min-width: 0; }
.kpi .cap { font-size: 10.5px; color: var(--muted); line-height: 1.35; margin-top: 4px; min-height: 28px; }
.kpi .spark { width: 92px; height: 58px; flex-shrink: 0; position: relative; }
.kpi .spark .d { position: absolute; top: -2px; right: 0; }

.chart { width: 100%; height: 260px; }
.chart.tall { height: 300px; }
.donut-wrap { display: flex; align-items: center; gap: 12px; }
.donut-wrap .chart { height: 250px; flex: 1; }
.legend { display: flex; flex-direction: column; gap: 10px; min-width: 120px; }
.legend .li { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend .sw { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.legend .sw.striped { background: repeating-linear-gradient(45deg, #c9ccd3 0 2px, #f6f8fc 2px 4px); border: 1px solid #c9ccd3; }
.legend .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.stat { display: flex; flex-direction: column; }
.stat .big { margin-top: 18px; }
.stat .muted { font-size: 11px; margin-top: 4px; }

.list { display: flex; flex-direction: column; margin-top: 8px; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.list .item:last-child { border-bottom: 0; }
.list .rank { width: 22px; height: 22px; border-radius: 6px; background: #fff; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.list .sku { font-weight: 500; font-variant-numeric: tabular-nums; }
.list .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--bar); overflow: hidden; }
.list .bar i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }
.list .num { min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.tag.ok { background: var(--good-bg); color: var(--good); }
.tag.out { background: #eef0f4; color: var(--ink-2); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.new { background: #e8effd; color: var(--blue); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

.alert {
  display: flex; gap: 10px; align-items: flex-start; background: var(--warn-bg); color: #7a4c06; border-radius: 12px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 12px; line-height: 1.5;
}
.alert b { font-weight: 600; }
.alert .btn { margin-left: auto; }

/* ---------------------------------------------------------------- table */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.search {
  display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 999px; padding: 8px 14px; min-width: 240px; flex: 0 1 320px;
  border: 1px solid var(--line);
}
.search input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 12px; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; user-select: none; }
.toolbar .spacer { flex: 1; }

.table-wrap { overflow-x: auto; background: #fff; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #eef1f6; white-space: nowrap; }
th { font-size: 11px; font-weight: 500; color: var(--muted); background: #fafbfd; position: sticky; top: 0; text-transform: uppercase; letter-spacing: .03em; }
th:first-child, td:first-child { text-align: left; }
td.l, th.l { text-align: left; }
tbody tr:hover td { background: #f7f9fd; }
td.zero { color: #c3c6cc; }
td.chg { color: var(--bad); font-weight: 600; }
td.sku { font-weight: 500; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 4px 0; color: var(--muted); font-size: 12px; }
.pager .btns { display: flex; gap: 6px; }
.icon-btn { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.icon-btn:hover { color: var(--bad); background: var(--bad-bg); }

/* ---------------------------------------------------------------- settings */
.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field label { font-size: 12px; color: var(--ink-2); }
.input, textarea.input {
  border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; outline: none; width: 100%;
}
.input:focus { border-color: var(--blue); }
textarea.input { min-height: 110px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.rules td, .rules th { padding: 6px 8px; text-align: left; }
.rules .input { padding: 6px 8px; }
.help { font-size: 11.5px; color: var(--muted); line-height: 1.6; margin-top: 10px; }
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5df; border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(18px); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 12px; margin-top: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------------------------------------------------------------- drawer & toast */
.drawer-mask { position: fixed; inset: 0; background: rgba(34,36,54,.28); display: none; z-index: 40; }
.drawer-mask.open { display: block; }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: min(560px, 100vw); background: var(--shell); z-index: 41;
  transform: translateX(100%); transition: transform .25s ease; padding: 20px; overflow-y: auto;
}
.drawer.open { transform: none; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 13px; opacity: 0; transition: all .2s; z-index: 60; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.progress { height: 4px; background: var(--bar); border-radius: 2px; overflow: hidden; width: 120px; }
.progress i { display: block; height: 100%; background: var(--blue); width: 0; transition: width .3s; }
.empty { text-align: center; padding: 40px 0; color: var(--muted); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .row3 > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .shell { margin: 0; border-radius: 0; padding: 16px 16px 84px; grid-template-columns: 1fr; min-height: 100vh; }
  .brand { display: none; }
  .topbar { grid-column: 1; flex-wrap: wrap; }
  .topbar h1 { font-size: 17px; }
  .sync-pill .meta { display: none; }
  main { grid-column: 1; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; flex-direction: row; justify-content: center; padding: 10px; z-index: 30;
    background: rgba(238,242,248,.95); backdrop-filter: blur(8px); grid-row: auto;
  }
  .sidebar .nav { flex-direction: row; }
  .sidebar .bottom { display: none; }
  .nav-btn .tip { display: none; }
  .kpis, .row2, .row3, .row4, .settings { grid-template-columns: minmax(0, 1fr); }
  .row3 > :first-child { grid-column: auto; }
  .search { flex: 1 1 100%; }
}

/* ---------------------------------------------------------------- v2: pager, thumbs, warehouses */
.split { display: inline-flex; gap: 6px; }
.pager { flex-wrap: wrap; gap: 10px; }
.pager-left { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pager-left label { display: inline-flex; align-items: center; gap: 6px; }
.pager .btns { flex-wrap: wrap; }
.pg {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 12px; font-variant-numeric: tabular-nums;
}
.pg:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.pg.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.pg:disabled { opacity: .4; cursor: default; }
.pg-gap { align-self: center; color: var(--muted); padding: 0 2px; }
.pg-jump { width: 56px; height: 32px; text-align: center; padding: 0 6px; }

.prod { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.thumb {
  width: 40px; height: 40px; border-radius: 10px; background: var(--shell); object-fit: contain; flex-shrink: 0;
  border: 1px solid var(--line); position: relative;
}
.thumb-ph { display: grid; place-items: center; color: #c3c6cc; }
.prod .nm { font-size: 11px; color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 400; }
.zoom { position: fixed; z-index: 70; pointer-events: none; background: #fff; padding: 6px; border-radius: 14px; box-shadow: 0 16px 40px -12px rgba(34,36,54,.4); display: none; }
.zoom img { width: 220px; height: 220px; object-fit: contain; display: block; border-radius: 10px; }
.list .thumb { width: 34px; height: 34px; border-radius: 8px; }

.rule-box { background: #fff; border-radius: 12px; padding: 12px 14px; margin-top: 10px; display: grid; gap: 6px; font-size: 12.5px; line-height: 1.6; }
.rule-box b { font-weight: 600; }
.wh-group { margin-top: 14px; }
.wh-group h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.wh-group h4 .muted { font-weight: 400; }
.wh-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 7px 10px; background: #fff; border-radius: 10px; margin-bottom: 6px; }
.wh-row .code { font-weight: 500; font-variant-numeric: tabular-nums; }
.wh-row .code .tag { margin-left: 6px; }
.wh-row .meta { font-size: 11px; color: var(--muted); text-align: right; white-space: nowrap; }
.wh-row.unmapped { outline: 1.5px solid #f3c77a; }

/* ---------------------------------------------------------------- v3: selection + export menu */
th.ck, td.ck { width: 36px; padding-left: 14px; padding-right: 0; text-align: left; }
.ck input, .menu-opt input { width: 15px; height: 15px; accent-color: var(--blue); cursor: pointer; vertical-align: middle; }
tbody tr.picked td { background: #eef4ff; }
.sel-info { font-size: 12px; color: var(--ink-2); }
.sel-info b { color: var(--blue); font-weight: 600; }
.link { border: 0; background: none; color: var(--blue); cursor: pointer; padding: 0 2px; font-size: 12px; }
.dropdown { position: relative; }
.export-menu { top: 40px; min-width: 230px; }
.export-menu button { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.export-menu button:disabled { color: #c3c6cc; cursor: default; background: none; }
.export-menu .n { font-size: 11px; color: var(--muted); background: var(--shell); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
.export-menu .menu-opt { display: flex; padding: 10px 10px 6px; margin-top: 4px; border-top: 1px solid var(--line); font-size: 12px; }
.export-menu button[hidden] { display: none; }
th.ck + th, td.ck + td { text-align: left; }
