:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2329;
  --muted: #646a73;
  --border: #dee0e3;
  --primary: #3370ff;
  --primary-soft: #eef4ff;
  --success: #00b42a;
  --success-soft: #e8ffea;
  --warning: #ff7d00;
  --warning-soft: #fff7e8;
  --danger: #f54a45;
  --danger-soft: #ffece8;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(31, 35, 41, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.app-shell {
  max-width: 920px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 78px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 8px; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: linear-gradient(135deg, #3370ff, #5b8cff);
}
.brand-title { font-weight: 700; font-size: 16px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.demo-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  background: #fffbe6;
  color: #8c5a00;
}

.chip-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn.active {
  background: var(--primary);
  color: #fff;
}

.main-container { padding: 14px 14px 24px; }

.loading-box {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

/* 顶部积分卡 */
.hero-card {
  background: linear-gradient(135deg, #2556d6 0%, #3370ff 60%, #5b8cff 100%);
  color: #fff;
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 8px 22px rgba(51, 112, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.hero-user { font-size: 13px; opacity: 0.9; margin-bottom: 4px; }
.hero-points { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.1; }
.hero-points span { font-size: 14px; font-weight: 500; opacity: 0.9; margin-left: 4px; }
.hero-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.hero-pill {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

/* 分类筛选 */
.cat-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 12px;
  scrollbar-width: none;
}
.cat-strip::-webkit-scrollbar { display: none; }
.cat-pill {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.cat-pill.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
  font-weight: 600;
}

/* 商品网格 */
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (min-width: 700px) {
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
}

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(31, 35, 41, 0.06);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}
.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(31, 35, 41, 0.08);
}

.product-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #f0f2f5;
  overflow: hidden;
}
.product-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.badge-row {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 5px;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
}
.badge-new { background: #ff4d4f; color: #fff; }
.badge-video { background: rgba(15, 23, 42, 0.78); color: #fff; }

.product-info {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.product-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-foot {
  margin-top: auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.price-tag {
  color: var(--primary);
  font-weight: 800;
  font-size: 16px;
}
.price-tag small { font-size: 11px; font-weight: 500; margin-left: 2px; }
.afford-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
}
.afford-ok { background: var(--success-soft); color: var(--success); font-weight: 600; }
.afford-no { background: #f2f3f5; color: var(--muted); }

/* 底部导航 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 920px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}
.nav-item {
  flex: 1;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
}
.nav-item .nav-icon { font-size: 18px; }
.nav-item.active { color: var(--primary); font-weight: 700; }

/* 模态层 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 680px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}
.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 92vh;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { max-width: 720px; }
@media (min-width: 680px) {
  .modal-sheet { border-radius: 18px; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.icon-close {
  border: none;
  background: #f2f3f5;
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; font-size: 14px; color: var(--text);
}
.modal-body {
  padding: 16px 18px 24px;
  overflow-y: auto;
}

/* 媒体轮播 */
.media-stage {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.media-stage img, .media-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0f172a;
}
.media-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
}
.media-thumb-btn {
  position: relative;
  flex: 0 0 64px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  padding: 0;
  background: #1e293b;
  cursor: pointer;
}
.media-thumb-btn.active { border-color: var(--primary); }
.media-thumb-btn img { width: 100%; height: 100%; object-fit: cover; }
.media-thumb-video {
  color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
}

/* 通用卡片与表单 */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid rgba(31, 35, 41, 0.06);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.section-title { font-size: 14px; font-weight: 700; margin: 14px 0 8px; }
.muted { color: var(--muted); font-size: 12px; }

.spec-group { margin-bottom: 10px; }
.spec-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.spec-options { display: flex; flex-wrap: wrap; gap: 8px; }
.spec-chip {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
}
.spec-chip.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #f2f3f5; color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.swap-banner {
  background: var(--warning-soft);
  border: 1px solid #ffd8a8;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.status-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.st-pending_purchase { background: var(--warning-soft); color: var(--warning); }
.st-ordered { background: var(--primary-soft); color: var(--primary); }
.st-shipped { background: var(--success-soft); color: var(--success); }
.st-cancelled { background: #f2f3f5; color: var(--muted); }

/* 列表行 */
.ledger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f0f1f3;
}
.ledger-row:last-child { border-bottom: none; }
.delta-pos { color: var(--success); font-weight: 700; font-size: 15px; }
.delta-neg { color: var(--text); font-weight: 700; font-size: 15px; }

/* 管理后台 */
.admin-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 14px;
}
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}
.kpi-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(31, 35, 41, 0.06);
}
.kpi-num { font-size: 24px; font-weight: 800; color: var(--primary); }
.kpi-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.code-block {
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
}

.toast {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
