:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1f2430;
  --gold: #f5b83d;
  --gold-soft: #fdf3df;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
code { word-break: break-all; }

/* 按钮 loading */
.btn.is-loading { opacity: 0.85; pointer-events: none; }
.spinner {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid rgba(128, 128, 128, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 面包屑 */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin: 2px 0 14px;
}
.crumb-link { color: var(--muted); }
.crumb-link:hover { color: var(--text); }
.crumb-current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--line); }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: cover;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.lang-link {
  padding: 5px 12px;
  font-size: 13px;
  color: var(--muted);
}

.lang-link.active {
  background: var(--primary);
  color: #fff;
}

.user-email {
  font-size: 13px;
  color: var(--muted);
}

.announcement {
  background: #fef2f2;
  color: #dc2626;
  font-weight: 700;
  text-align: center;
  font-size: 14px;
  padding: 10px 16px;
}

.offer-badge {
  display: inline-block;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  margin: 6px 0;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0 0;
  font-size: 15px;
}

.total-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.discount-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
  padding-top: 4px;
}

.discount-value {
  color: #dc2626;
  font-weight: 600;
}

/* ---------- 布局 ---------- */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px;
  flex: 1;
}

.home-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.sidebar-title {
  margin: 0 0 12px;
  font-size: 15px;
}

.cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cat-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.cat-link.active,
.cat-link:hover {
  background: var(--bg);
}

.cat-icon { font-size: 16px; }
.cat-name { flex: 1; }
.cat-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 8px;
}

.catalog { flex: 1; min-width: 0; }

/* ---------- 商品卡片 ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
  align-items: stretch;
}

.product-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.14);
}

.card-img {
  aspect-ratio: 1 / 1;
  background: #f5f6f8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
}

.card-img img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.card-body {
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.45;
  min-height: 44px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

.tag {
  font-size: 12px;
  color: var(--muted);
  background: #f3f4f6;
  border-radius: 999px;
  padding: 3px 10px;
}

.card-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 6px;
}

.card-foot-left {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.card-price {
  font-weight: 700;
  color: var(--gold);
  font-size: 18px;
  white-space: nowrap;
}

.card-stock {
  font-size: 12px;
  color: var(--muted);
}

.btn-buy {
  flex-shrink: 0;
  padding: 9px 18px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { opacity: 0.9; }
.btn-ghost { border-color: var(--line); background: var(--card); }
.btn-block { width: 100%; }
.btn-danger-sm {
  border: none;
  background: #fdecec;
  color: var(--danger);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.btn-ghost-sm {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px;
}

/* ---------- 表单 ---------- */
.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; }

.code-row {
  display: flex;
  gap: 8px;
}

.code-row input { flex: 1; }

.code-hint {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}

.qty {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.qty button {
  width: 36px;
  height: 38px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 18px;
}

.qty input {
  width: 64px;
  text-align: center;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
}

.alert {
  background: #fdecec;
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

/* ---------- 认证页 ---------- */
.auth-page {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.auth-card h1 {
  margin: 0 0 20px;
  font-size: 20px;
}

.auth-links {
  display: flex;
  justify-content: flex-end;
  margin: 6px 0 14px;
  font-size: 13px;
}

.auth-alt {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.auth-alt a { color: var(--primary); }

/* ---------- 详情 / 支付 ---------- */
.detail-card {
  display: flex;
  gap: 24px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.detail-media {
  flex: 0 0 42%;
  border-radius: 12px;
  overflow: hidden;
  background: #eee;
}

.detail-media img { width: 100%; height: 100%; object-fit: cover; }

.detail-info { flex: 1; min-width: 0; }
.detail-name { margin: 0 0 10px; font-size: 22px; }
.detail-price { font-size: 24px; font-weight: 700; color: var(--gold); margin: 12px 0 4px; }

.detail-stock { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.detail-desc {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-top: 20px;
}

.desc-text { white-space: pre-wrap; color: var(--text); }

.payment-card {
  max-width: 560px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.payment-title { margin: 0 0 16px; font-size: 19px; }

.pay-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.pay-address { margin: 16px 0; }

.address-box {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
}

.address-box code { flex: 1; font-size: 13px; }

.pay-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

.countdown {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

.credential-box {
  margin-top: 18px;
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
}

.credential-box pre {
  white-space: pre-wrap;
  word-break: break-all;
  margin: 8px 0 0;
}

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th, .table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.table th { color: var(--muted); font-weight: 600; }

.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions form { margin: 0; }

.thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}

.cell-pre {
  white-space: pre-wrap;
  word-break: break-all;
  max-width: 260px;
  margin: 0;
  font-size: 12px;
}

.status-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  background: var(--bg);
  color: var(--muted);
}

.status-delivered { background: #e8f6ec; color: #16794a; }
.status-closed { background: #fdecec; color: var(--danger); }
.status-pending_payment { background: var(--gold-soft); color: #8a5a00; }

/* ---------- 后台 ---------- */
.admin-topbar { background: var(--primary); }
.admin-topbar .brand-name, .admin-topbar .user-email { color: #fff; }
.admin-topbar .user-email { color: #cbd2d9; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}

.stat-num {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.cat-img {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.admin-section {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 20px;
}

.admin-section h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

.admin-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-top: 14px;
}

.admin-form input,
.admin-form select,
.admin-form textarea { min-width: 140px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.grid-form textarea { grid-column: span 2; }

.tag-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.check input { width: auto; }

.file-label {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px 16px;
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .home-layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .cat-list { flex-direction: row; flex-wrap: wrap; }
  .cat-link { flex: 1 1 auto; }
  .detail-card { flex-direction: column; }
  .detail-media { flex: 0 0 auto; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form textarea { grid-column: span 1; }
}

@media (max-width: 560px) {
  .topbar-inner { padding: 10px 12px; }
  .topnav { gap: 10px; width: 100%; justify-content: flex-start; }
  .brand { font-size: 16px; }
  .product-grid { grid-template-columns: 1fr; }
  .card-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .card-foot-left { justify-content: space-between; }
  .btn-buy { width: 100%; }
  .admin-form { flex-direction: column; align-items: stretch; }
  .admin-form input, .admin-form select, .admin-form textarea { min-width: 0; width: 100%; }
  .pay-row { flex-direction: column; gap: 4px; }
  .address-box { flex-direction: column; align-items: stretch; }
  .auth-card { padding: 22px 18px; }
}
