:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #1c2024;
  --muted: #7a8290;
  --line: #e4e7ec;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --low: #fef3f2;
  --low-text: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--low-text); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* 登录 */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-card {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 18px; margin: 0; }
.login-card p { margin: 0; }
input, select, button {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
.login-card button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  padding: 10px;
  font-weight: 600;
}

/* 顶栏 */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; }
.tabs { display: flex; gap: 6px; }
.tabs button {
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
}
.tabs button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.who { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.who button { padding: 6px 10px; }

main { padding: 16px 20px 40px; max-width: 1400px; margin: 0 auto; }

.filters {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filters label { display: flex; align-items: center; gap: 6px; }
.filters select { min-width: 180px; }
.check { gap: 4px; }

/* KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi span { color: var(--muted); font-size: 12px; }
.kpi strong { font-size: 22px; font-variant-numeric: tabular-nums; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.card h2 {
  font-size: 14px;
  margin: 0 0 10px;
  display: flex;
  gap: 6px;
  align-items: baseline;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
#storeTable tbody tr[data-store] { cursor: pointer; }
#storeTable tbody tr[data-store]:hover { background: var(--accent-soft); }

tr.low { background: var(--low); }
tr.low td:last-child { color: var(--low-text); font-weight: 600; }

/* 订单 */
.orders { display: flex; flex-direction: column; gap: 8px; }
.order { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.order summary {
  display: grid;
  grid-template-columns: 130px 110px 1fr auto;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  background: #fbfcfd;
  list-style: none;
}
.order summary::-webkit-details-marker { display: none; }
.ono { font-variant-numeric: tabular-nums; color: var(--accent); }
.odate, .ostore { color: var(--muted); }
.oamt { font-weight: 600; font-variant-numeric: tabular-nums; }
.lines { background: #fff; }
@media (max-width: 700px) {
  .order summary { grid-template-columns: 1fr auto; }
  .odate, .ostore { display: none; }
}

/* ===== 出库流向 ===== */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  transition: border-color .15s, box-shadow .15s;
}
.tile:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(37,99,235,.12); }
.tile strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.tile-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.tile-label i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tile-unit { font-size: 11px; color: var(--muted); }
.tile.total { background: var(--accent-soft); border-color: #c7d7fe; }

/* ===== 子标签 ===== */
.subtabs { display: flex; gap: 8px; margin-bottom: 12px; }
.subtabs button {
  padding: 6px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
}
.subtabs button.active { background: var(--accent-soft); color: var(--accent); border-color: #c7d7fe; font-weight: 600; }

/* ===== 图表 ===== */
.chart { min-height: 240px; }
.svg-chart { width: 100%; height: auto; }
.svg-pie { width: 220px; height: 220px; flex: none; }
.pie-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legend { display: flex; flex-direction: column; gap: 6px; min-width: 190px; }
.legend .lg { display: grid; grid-template-columns: 10px 1fr auto auto; gap: 6px; align-items: center; font-size: 12px; }
.legend .lg i { width: 10px; height: 10px; border-radius: 2px; }
.legend .lg b { font-variant-numeric: tabular-nums; }

/* ===== 抽屉 ===== */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 92vw);
  background: #fff; border-left: 1px solid var(--line); z-index: 50;
  display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(16,24,40,.12);
}
.drawer header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); position: static;
}
.drawer-title { font-weight: 700; }
.drawer-body { padding: 14px 16px 40px; overflow: auto; }

/* ===== 其它 ===== */
.link { border: none; background: none; color: var(--accent); padding: 0; font: inherit; cursor: pointer; text-decoration: underline dotted; }
.link:hover { text-decoration: underline; }
.ghost { background: #fff; }
.banner { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; }
.banner.ok { background: #ecfdf3; border: 1px solid #abefc6; }
.banner.warn { background: #fffaeb; border: 1px solid #fedf89; }
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .drawer { width: 100vw; }
}
