:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1c2024;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -8px rgba(16, 24, 40, .12);
}

* { box-sizing: border-box; }

/* 必须显式声明：下面 .admin-shell / .login-page 的 display 会覆盖 UA 的 [hidden] 规则 */
[hidden] { display: none !important; }

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

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

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 20px; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner { display: flex; align-items: center; gap: 20px; height: 60px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
/* 迷你猫 logo：内联 SVG，跟随主题色 */
.brand .logo-cat { width: 24px; height: 24px; flex: none; color: var(--accent); }
.topnav { margin-left: auto; display: flex; gap: 6px; }
.topnav a {
  color: var(--muted); padding: 7px 12px; border-radius: 9px; font-size: 14px;
}
.topnav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- 通用 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.section { margin: 26px 0; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.section-head h2 { font-size: 18px; margin: 0; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; }

.hero { padding: 34px 30px; text-align: center; }
.hero h1 { font-size: 26px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0 0 22px; }

/* ---------- 表单 ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 96px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg); filter: none; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }

/* ---------- 枚码展示 ---------- */
.codebox {
  margin-top: 18px; padding: 18px; border-radius: 12px;
  background: var(--accent-soft); border: 1px dashed var(--accent);
  text-align: center;
}
.codebox .label { font-size: 13px; color: var(--muted); }
.codebox .code {
  font-family: ui-monospace, Consolas, monospace; font-size: 24px; font-weight: 700;
  letter-spacing: 2px; color: var(--accent); margin: 8px 0 12px; word-break: break-all;
}
.hint { font-size: 13px; color: var(--muted); }

/* ---------- 商品 ---------- */
.merchant-block { margin-bottom: 22px; }
.merchant-name { font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.merchant-name .tag {
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: var(--bg); padding: 2px 8px; border-radius: 999px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.product { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.product h3 { margin: 0; font-size: 16px; }
.product .meta { color: var(--muted); font-size: 13px; }
.product .price { font-size: 20px; font-weight: 700; color: var(--accent); }
.product .price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.product .stock { font-size: 12px; }
.product .stock.no { color: var(--danger); }
.product .stock.yes { color: var(--ok); }
.product .btn { margin-top: auto; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
.toast.error { background: var(--danger); }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin: 12px 0; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-mask.show { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 440px; }
.modal h3 { margin: 0 0 4px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--surface); }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--bg); font-weight: 600; font-size: 13px; color: var(--muted); }
tbody tr:hover { background: #fafbff; }
td.mono, .mono { font-family: ui-monospace, Consolas, monospace; }
.empty { padding: 34px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.gray { background: #f3f4f6; color: #4b5563; }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }

/* ---------- 后台布局 ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.side {
  width: 210px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .brand { padding: 6px 10px 16px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav button {
  text-align: left; padding: 9px 12px; border: 0; background: none; font: inherit;
  color: var(--muted); border-radius: 9px; cursor: pointer;
}
.side nav button:hover { background: var(--bg); color: var(--text); }
.side nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { flex: 1; padding: 24px 28px; min-width: 0; }
.main h1 { font-size: 20px; margin: 0 0 18px; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 140px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 16px; }
.stat .n { font-size: 24px; font-weight: 700; }
.stat .t { font-size: 13px; color: var(--muted); }

.pager { display: flex; gap: 10px; align-items: center; margin-top: 14px; font-size: 14px; color: var(--muted); }

.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; padding: 30px; }

pre.raw { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; overflow: auto; font-size: 13px; }

@media (max-width: 720px) {
  .admin-shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 16px; }
  .topnav a { padding: 7px 9px; }
}
