:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6b7688;
  --line: #e6eaf2;
  --primary: #2f6fed;
  --primary-soft: #eaf1ff;
  --green: #128a4a;
  --green-soft: #e8f7ee;
  --red: #c0392b;
  --red-soft: #fdecea;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --purple: #7c3aed;
  --purple-soft: #f2ecfe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 6px 18px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  background: #f1f4f9;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.05rem 0.35rem;
  font-size: 0.86em;
  color: #334155;
}

.app { display: flex; min-height: 100vh; }

/* ---------- 左侧导航 ---------- */
.sidebar {
  width: 238px;
  flex: 0 0 238px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  border-radius: 11px;
  font-size: 20px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-title {
  margin: 16px 10px 6px;
  color: #98a2b3;
  font-size: 11px;
  letter-spacing: 0.08em;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  color: #475467;
  font-size: 14px;
}
.nav a span { width: 18px; text-align: center; }
.nav a:hover { background: #f5f7fb; text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.external { font-size: 13px; color: var(--muted); }
.logout {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.logout:hover { background: #f5f7fb; color: var(--text); }

/* ---------- 内容 ---------- */
.content {
  flex: 1;
  min-width: 0;
  padding: 28px 34px 60px;
  max-width: 1240px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 25px; letter-spacing: -0.01em; }
.sub { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.user-head { display: flex; align-items: center; gap: 14px; }

.back { margin-bottom: 12px; font-size: 13px; }

/* ---------- 卡片与统计 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: 0 0 40px;
}
.stat-icon.blue { background: var(--primary-soft); }
.stat-icon.green { background: var(--green-soft); }
.stat-icon.amber { background: var(--amber-soft); }
.stat-icon.purple { background: var(--purple-soft); }
.stat span { display: block; color: var(--muted); font-size: 12.5px; }
.stat strong { display: block; font-size: 24px; line-height: 1.3; }
.stat small { color: #98a2b3; font-size: 11.5px; }

.stat-grid.small { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mini-stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.mini-stat span { color: var(--muted); font-size: 12.5px; }
.mini-stat strong { font-size: 18px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel.narrow { max-width: 620px; }
.hint-panel { font-size: 13.5px; color: #475467; }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.two > .panel { margin-bottom: 0; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll {
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.table-wrap.scroll thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
tr.row-off td, tr.disabled td { opacity: 0.55; }
td.empty, .empty { color: var(--muted); text-align: center; padding: 26px 8px; }
.muted { color: var(--muted); }

/* ---------- 徽标与数值 ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.off { background: #f1f3f7; color: #667085; }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }

.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.plus { color: var(--green); }
.amount.minus { color: var(--red); }

.bar {
  height: 8px;
  border-radius: 999px;
  background: #eef2f8;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2f6fed, #7c3aed);
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #eef2f8;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { filter: brightness(0.97); text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); color: #344054; }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.ok { background: var(--green-soft); color: var(--green); }
.btn.small { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field small { color: #98a2b3; font-size: 11.5px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #d6dde8;
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: 14px;
}
textarea { resize: vertical; min-height: 80px; }
.field.full { grid-column: 1 / -1; }
input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="checkbox"] { width: auto; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: end; }
.form-grid.form-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-row .grow { flex: 1; min-width: 160px; }
.form-row .check-field { padding-bottom: 9px; }
.form-actions { display: flex; gap: 8px; }
.form-actions.full { grid-column: 1 / -1; }
.form-column { display: flex; flex-direction: column; gap: 14px; }
.quick-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.check-field { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: #344054; }
.save-bar {
  display: flex;
  gap: 10px;
  position: sticky;
  bottom: 16px;
  background: rgba(245, 247, 251, 0.92);
  padding: 12px 0;
  backdrop-filter: blur(4px);
}

/* ---------- 用户 ---------- */
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell small { display: block; color: var(--muted); font-size: 11.5px; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: 0 0 34px;
}
.avatar.xl { width: 52px; height: 52px; flex-basis: 52px; font-size: 20px; }

/* ---------- 商品 ---------- */
.collapsible summary {
  cursor: pointer;
  font-weight: 600;
  color: #344054;
  list-style: none;
}
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible[open] summary { margin-bottom: 14px; }

.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.item-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.item-card.is-off { opacity: 0.72; }
.item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.item-top h3 { margin: 2px 0 0; font-size: 16px; }
.id-chip { color: var(--muted); font-size: 12px; }
.item-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.item-meta div { background: #f8fafc; border-radius: 9px; padding: 8px 10px; }
.item-meta span { display: block; color: var(--muted); font-size: 11.5px; }
.item-meta strong { font-size: 14px; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.item-details { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--line); padding-top: 10px; }
.item-details summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }

.empty-card {
  background: #fff;
  border: 1px dashed #d6dde8;
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-card.big { margin-top: 12vh; }
.empty-card h2 { color: var(--text); }

/* ---------- 其他 ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: #f4f7fd;
  border: 1px solid var(--line);
  color: #475467;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
}
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.link { font-size: 13px; }
.callout {
  margin-top: 14px;
  background: var(--primary-soft);
  color: #1e4bb8;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
}
.flash {
  background: var(--green-soft);
  border: 1px solid #b9e4c9;
  color: #0f6b3a;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 13.5px;
}
.flash.error { background: var(--red-soft); border-color: #f3c1bb; color: var(--red); }

/* ---------- 搜索 ---------- */
.searchbar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.searchbar input { flex: 1; min-width: 0; }
.searchbar .btn { flex: 0 0 auto; }

/* ---------- 登录页 ---------- */
html { min-height: 100%; }
html.auth-html {
  background: linear-gradient(160deg, #eef3ff 0%, #f7f9fc 55%, #fdf6ee 100%);
  background-attachment: fixed;
}
body.auth-page {
  min-height: 100vh;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(400px, 100%);
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.1);
  padding: 30px 28px;
}
.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--primary-soft);
  display: grid;
  place-items: center;
  font-size: 24px;
  margin-bottom: 14px;
}
.auth-card h1 { margin: 0; font-size: 22px; }
.auth-card .sub { margin: 4px 0 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card .hint { margin-top: 16px; }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .stat-grid, .stat-grid.small { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .item-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-basis: auto;
    height: auto;
    position: static;
    padding: 14px 14px 10px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding-bottom: 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav-title { display: none; }
  .nav a { padding: 7px 10px; font-size: 13px; }
  .sidebar-foot { flex-direction: row; justify-content: space-between; align-items: center; margin-top: 8px; padding-top: 10px; }
  .logout { width: auto; }
  .content { padding: 18px 14px 50px; }
  .stat-grid, .stat-grid.small { grid-template-columns: 1fr 1fr; gap: 10px; }
  .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 21px; }
  .item-meta { grid-template-columns: 1fr 1fr; }
}
