:root {
  --brand: #e60012;
  --brand-dark: #b3000e;
  --brand-soft: #fff1f1;
  --ink: #1f2329;
  --muted: #6b7280;
  --line: #ececec;
  --bg: #f5f6f8;
  --radius: 16px;
  --shadow: 0 4px 16px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 14px 44px rgba(17, 24, 39, 0.16);
  --page-padding-h: 24px;
  --gap: 18px;
}

@media (max-width: 768px) {
  :root { --page-padding-h: 12px; --gap: 12px; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  padding: 14px var(--page-padding-h);
  background: transparent;
}
.topbar .topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(17,24,39,.08);
  backdrop-filter: blur(6px);
}
.topbar .topbar-actions .btn,
.topbar .topbar-actions .role-badge {
  white-space: nowrap;
}
.topbar .hint { color: var(--muted); font-size: 13px; }

@media (max-width: 768px) {
  .topbar { padding: 10px var(--page-padding-h); }
  .topbar .topbar-actions {
    gap: 6px; padding: 4px 6px;
    background: rgba(255,255,255,.96);
  }
}

/* 游客/管理员标识 */
.role-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.role-badge.guest { background: #f0f1f3; color: var(--muted); }
.role-badge.admin { background: var(--brand-soft); color: var(--brand); }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #d0d0d0; background: #fafafa; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--brand); border-color: #f3c2c2; background: #fff; }
.btn.danger:hover { background: var(--brand-soft); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon { padding: 6px 9px; }

/* ============ 工具栏 ============ */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap);
  padding: var(--gap) var(--page-padding-h) 0;
}
.toolbar .search {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.toolbar .search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.toolbar .search input {
  border: none; outline: none; flex: 1; font-size: 14px; background: transparent;
}
.toolbar .group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ============ 统计条 ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  padding: var(--gap) var(--page-padding-h) 0;
}
.stat-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease;
  text-align: center;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .n { font-size: 24px; font-weight: 700; color: var(--brand); }
.stat-card .l { font-size: 13px; color: var(--muted); margin-top: 4px; }

@media (max-width: 768px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat-card { padding: 12px 8px; }
  .stat-card .n { font-size: 20px; }
  .stat-card .l { font-size: 11px; }
}

/* ============ 商品网格 ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--gap);
  padding: var(--gap) var(--page-padding-h) 44px;
}

/* H5 适配：每行展示两个商品 */
@media (max-width: 768px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--gap);
    padding: var(--gap) var(--page-padding-h) 32px;
  }
  .card .body { padding: 10px 11px 12px; gap: 6px; }
  .card .name { font-size: 13px; line-height: 1.35; }
  .card .price { font-size: 15px; }
}

/* ============ 公司介绍 ============ */
.company-intro {
  position: relative;
  background: linear-gradient(135deg, #1f7a4d 0%, #2e8b57 55%, #3cb371 100%);
  color: #fff;
  margin: var(--gap) var(--page-padding-h) 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.company-intro::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.ci-inner { position: relative; z-index: 1; padding: 26px 28px; }
.ci-brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.ci-logo {
  font-weight: 800; font-size: 26px; letter-spacing: 3px;
  background: rgba(255,255,255,.18); padding: 4px 12px; border-radius: 10px;
}
.ci-brand h1 { margin: 0; font-size: 20px; font-weight: 700; }
.ci-slogan { margin: 0 0 16px; opacity: .92; font-size: 14px; letter-spacing: .5px; }
.ci-body {
  display: flex; flex-direction: column; gap: 10px;
  font-size: 14px; line-height: 1.8; opacity: .96;
}
.ci-body p { margin: 0; }
.ci-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-top: 22px;
}
.ci-stat {
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px;
  padding: 16px 12px; text-align: center;
  backdrop-filter: blur(2px);
}
.ci-stat strong { display: block; font-size: 26px; font-weight: 800; margin-bottom: 4px; letter-spacing: 1px; }
.ci-stat span { display: block; font-size: 12px; opacity: .92; line-height: 1.45; }

@media (max-width: 768px) {
  .company-intro { margin: var(--gap) var(--page-padding-h) 0; border-radius: 12px; }
  .ci-inner { padding: 20px; }
  .ci-logo { font-size: 20px; padding: 3px 9px; }
  .ci-brand h1 { font-size: 16px; }
  .ci-slogan { font-size: 13px; margin-bottom: 12px; }
  .ci-body { font-size: 13px; gap: 8px; line-height: 1.7; }
  .ci-stats { grid-template-columns: 1fr; gap: 8px; margin-top: 16px; }
  .ci-stat { padding: 10px; }
  .ci-stat strong { font-size: 22px; }
}

/* ============ 批量操作栏 ============ */
.batch-bar {
  display: flex; align-items: center; gap: 16px;
  margin: 16px var(--page-padding-h) 0; padding: 12px 18px;
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
.batch-bar .select-all { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.batch-bar .batch-count { color: var(--muted); font-size: 13px; }
.batch-bar .btn-primary { margin-left: auto; }
.batch-bar .btn[disabled] { opacity: .5; cursor: not-allowed; }

/* 卡片右下角选择框（避免遮挡左上角序号） */
.card .pick {
  position: absolute; bottom: 8px; right: 8px; z-index: 5;
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.9); border-radius: 6px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.card .pick input { width: 16px; height: 16px; margin: 0; cursor: pointer; }

@media (max-width: 768px) {
  .batch-bar {
    margin: 12px var(--page-padding-h) 0; padding: 10px 12px; gap: 10px;
    flex-wrap: wrap; top: 0;
  }
  .batch-bar .select-all { font-size: 13px; }
  .batch-bar .batch-count { font-size: 12px; }
  .batch-bar .btn-primary { margin-left: 0; width: 100%; }
}
.card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  cursor: pointer;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: #e0e0e0; }
.card .thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: linear-gradient(135deg, #fafafa, #f0f0f0);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .thumb .ph { color: #c4c4c4; font-size: 40px; }
.card .thumb .rank {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.55); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.card .thumb .hot-badge {
  position: absolute; top: 8px; right: 8px;
  background: #ff4d4f; color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  box-shadow: 0 2px 6px rgba(255,77,79,.4);
}
.card .thumb .cat-badge {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(0,0,0,.5); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .name { font-weight: 600; font-size: 14px; line-height: 1.4; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.card .price { color: var(--brand); font-weight: 700; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 11px; }
.card .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.tag { background: var(--brand-soft); color: var(--brand); font-size: 11px; padding: 2px 8px; border-radius: 6px; }
.tag.gray { background: #f0f1f3; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 80px 20px; }
.empty .big { font-size: 48px; margin-bottom: 12px; }

/* ============ 弹窗 ============ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 760px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal.sm { max-width: 380px; }
.modal.lg { max-width: 1340px; }
.modal.lg .m-body { padding: 12px; }
.modal .m-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal .m-head h3 { margin: 0; font-size: 16px; }
.modal .m-body { padding: 20px; overflow: auto; }
.modal .m-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line); background: #fafafa;
}
.x { cursor: pointer; border: none; background: transparent; font-size: 22px; color: var(--muted); line-height: 1; }
.x:hover { color: var(--ink); }

/* ============ 表单 ============ */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; font-family: inherit; outline: none;
  background: #fff; transition: border-color .15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); }
.field textarea { resize: vertical; min-height: 70px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* 省份多选网格 */
.prov-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 10px;
  max-height: 150px; overflow-y: auto; padding: 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.prov { display: flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; user-select: none; }
.prov input { accent-color: var(--brand); }

/* 售后多选行 */
.chk-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.chk { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--brand); }
.mini { width: auto !important; flex: 1; min-width: 160px; padding: 7px 10px !important; }

/* ============ 详情页 ============ */
.detail-head { display: flex; gap: 16px; }
.detail-head .dthumb { width: 160px; height: 160px; border-radius: 10px; overflow: hidden; background: #f0f0f0; flex-shrink: 0; }
.detail-head .dthumb img { width: 100%; height: 100%; object-fit: cover; }
.detail-info { flex: 1; min-width: 0; }
.detail-info h2 { margin: 0 0 8px; font-size: 20px; }
.detail-info .kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; font-size: 13px; }
.detail-info .kv > div { display: flex; flex-wrap: wrap; gap: 4px; }
.detail-info .kv .k { color: var(--muted); white-space: nowrap; }
.section-title { margin: 18px 0 8px; font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.section-title .bar { width: 4px; height: 16px; background: var(--brand); border-radius: 2px; }

/* H5 适配：商品详情弹窗单列布局 */
@media (max-width: 768px) {
  .overlay { padding: 0; align-items: flex-end; }
  .overlay:has(.modal.sm) { align-items: center; padding: 20px; }
  .modal { max-width: 100%; width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
  .modal.sm { border-radius: 14px; }
  .modal .m-head { padding: 12px 16px; }
  .modal .m-body { padding: 14px 16px 20px; }
  .modal .m-foot { padding: 10px 16px; }

  .detail-head { flex-direction: column; gap: 12px; }
  .detail-head .dthumb { width: 100%; max-width: 260px; height: auto; aspect-ratio: 1/1; margin: 0 auto; }
  .detail-info h2 { font-size: 18px; margin-bottom: 10px; }
  .detail-info .kv { grid-template-columns: 1fr; gap: 10px 0; font-size: 14px; }

  .section-title { margin: 16px 0 10px; }
  .img-list .it { width: 72px; height: 72px; }
  .card-mini { padding: 10px; }
}

.img-list { display: flex; flex-wrap: wrap; gap: 8px; }
.img-list .it { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.img-list .it img { width: 100%; height: 100%; object-fit: cover; }
.img-list .it .del { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1; }

.card-mini { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.card-mini .ci { width: 36px; height: 36px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.card-mini .cmeta { flex: 1; min-width: 0; }
.card-mini .cmeta .cn { font-weight: 600; }
.card-mini .cmeta .cd { font-size: 11px; color: var(--muted); }

/* ============ Toast ============ */
.toast-wrap { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #323232; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: pop .2s ease;
  max-width: 80vw;
}
.toast.ok { background: #2e7d32; }
.toast.err { background: var(--brand-dark); }
@keyframes pop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ============ 登录 ============ */
.login-card { text-align: center; }
.login-card .lc-logo { font-size: 40px; }
.login-card h2 { margin: 6px 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* 隐藏管理类元素（游客态） */
body.guest .admin-only { display: none !important; }

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

/* ============ 模板管理 ============ */
.tmpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; padding: 4px; }
.tmpl-card {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 6px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.tmpl-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.tmpl-name { font-weight: 600; font-size: 15px; color: var(--ink); }
.tmpl-kind { font-size: 12px; color: var(--muted); }
.tmpl-acts { display: flex; gap: 8px; margin-top: 4px; }
.btn.mini { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.danger { background: #fff; color: #e11d48; border: 1px solid #f3c6d2; }
.btn.danger:hover { background: #fff1f3; }
.muted { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 2px 0 10px; }
.hint code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; color: #b3000e; font-size: 12px; }

/* 字段表单通用（modal 内） */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input[type="text"], .field input:not([type]), .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; box-sizing: border-box;
}
.field input[type="color"] { width: 56px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; vertical-align: middle; margin-right: 8px; }
.empty { text-align: center; padding: 40px; color: var(--muted); }

/* ============ 加载反馈（spinner / 阶段进度 / 图片骨架淡入） ============ */
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite; display: inline-block; vertical-align: -2px;
}
.spinner.brand { border-color: #fde2e6; border-top-color: var(--brand); }
.btn-loading { pointer-events: none; opacity: .78; }
@keyframes spin { to { transform: rotate(360deg); } }

.fetch-progress {
  display: flex; align-items: center; gap: 10px; margin-top: 4px;
  padding: 22px 14px; border: 1px dashed var(--line); border-radius: 10px;
  color: var(--muted); font-size: 13px;
}
.fetch-error { color: #c0392b; font-size: 13px; line-height: 1.6; }
.fetch-warn { color: #b45309; font-size: 13px; line-height: 1.6; }

.fetch-img-box { width: 120px; height: 120px; border-radius: 8px; margin: 8px 0;
  background: linear-gradient(135deg, #fafafa, #f0f0f0); overflow: hidden; }
.fetch-img-box img { width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .25s ease; }
.fetch-img-box img.ok { opacity: 1; }

/* 列表卡片缩略图：骨架 shimmer + 加载淡入 + 失败占位 */
.card .thumb.skeleton::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(100deg, #f2f2f2 40%, #fafafa 50%, #f2f2f2 60%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.card .thumb img { opacity: 0; transition: opacity .25s ease; }
.card .thumb img.ok { opacity: 1; }
