/* ===================================================================
   自动发卡网站 — 全站样式
   前台与后台共用。配色与组件统一由 CSS 变量控制。
   =================================================================== */

:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --border:    #e2e5ea;
  --text:      #1f2430;
  --muted:     #6b7280;
  --primary:   #4f46e5;
  --primary-h: #4338ca;
  --success:   #16a34a;
  --success-bg:#ecfdf5;
  --warning:   #d97706;
  --warning-bg:#fffbeb;
  --danger:    #dc2626;
  --danger-bg: #fef2f2;
  --info-bg:   #eff6ff;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

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

h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- 前台页眉 / 页脚 ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--primary); }
.brand-sub { color: var(--muted); font-weight: 400; font-size: .85em; }
.site-nav a { margin-left: 18px; color: var(--text); }
.site-nav a:hover { color: var(--primary); text-decoration: none; }

.main-content { padding: 28px 16px 48px; min-height: 60vh; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0 28px;
  color: var(--muted);
  font-size: .85rem;
  text-align: center;
}
.footer-contact { white-space: pre-line; }

/* ---------- 卡片 / 区块 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { margin-bottom: 14px; }

/* 商品格 */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .12s ease, box-shadow .12s ease;
}
.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(16, 24, 40, .12);
}
.product-name { font-weight: 600; font-size: 1.05rem; color: var(--text); }
.product-desc {
  color: var(--muted); font-size: .88rem; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.product-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;      /* 极窄画面时让徽章整块换行，而不是把价格折成两行 */
  margin-top: 2px;
}
.product-price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  line-height: 1.35;
}
/* 有数量折扣时的「起」字标记 */
.price-from {
  font-size: .72rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 3px;
}
.product-meta .badge { flex: none; }

/* ---------- 表单 ---------- */

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; }
.form-hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
textarea { resize: vertical; min-height: 110px; }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-block;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  background: var(--primary);
  color: #fff;
  transition: background .12s ease;
}
.btn:hover { background: var(--primary-h); text-decoration: none; color: #fff; }
.btn-block { display: block; width: 100%; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 12px; font-size: .85rem; }
.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; }

.inline-form { display: inline; }

/* ---------- 表格 ---------- */

.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: .9rem;
}
.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
.data-table th { background: var(--bg); font-weight: 600; color: var(--muted); }
.data-table tr:hover td { background: #fafbfc; }
/* 可换行字段（商品名称、卡密内容等）：给最小宽度，避免被其他不换行的字段挤到一字一行；
   overflow-wrap: anywhere 只在必要时才切断过长字符串，不像 break-all 会从单字中间随处断字 */
.data-table td.wrap { white-space: normal; overflow-wrap: anywhere; word-break: normal; min-width: 160px; }

/* ---------- 徽章 / 状态 ---------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.6;
}
.badge-gray    { background: var(--bg);        color: var(--muted); }
.badge-green   { background: var(--success-bg); color: var(--success); }
.badge-yellow  { background: var(--warning-bg); color: var(--warning); }
.badge-red     { background: var(--danger-bg);  color: var(--danger); }
.badge-blue    { background: var(--info-bg);    color: var(--primary); }

/* ---------- 提示消息 ---------- */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: #fecaca; }
.alert-info    { background: var(--info-bg);    color: var(--primary); border-color: #bfdbfe; }

/* ---------- 卡密显示 ---------- */

.code-list { display: flex; flex-direction: column; gap: 10px; }
.code-item {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  padding: 12px 14px;
  font-family: Consolas, "Courier New", monospace;
  font-size: .9rem;
  white-space: pre-wrap;
  word-break: break-all;
  position: relative;
  /* 右侧预留空间，避免长卡密被复制按钮盖住 */
  padding-right: 76px;
  min-height: 42px;
  display: flex;
  align-items: center;
}
.code-item .code-text { flex: 1; }
.copy-btn {
  position: absolute; top: 50%; right: 8px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, .12);
  color: #e2e8f0;
  border: none; border-radius: 6px;
  padding: 4px 10px; font-size: .78rem; cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.copy-btn:hover { background: rgba(255, 255, 255, .25); }
.copy-btn.copied { background: var(--success); color: #fff; }

/* 复制全部按钮的成功状态 */
#copy-all-btn.copied { background: var(--success); }

/* ---------- 订单状态页 ---------- */

.order-summary { list-style: none; margin: 0 0 16px; padding: 0; }
.order-summary li {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 8px 0; border-bottom: 1px dashed var(--border);
}
.order-summary li span:first-child { color: var(--muted); }
.order-summary li span:last-child { text-align: right; word-break: break-all; }

.status-hero { text-align: center; padding: 10px 0 4px; }
.status-hero .status-icon { font-size: 2.4rem; }

/* ---------- 统计砖（后台仪表盘） ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat-label { color: var(--muted); font-size: .82rem; margin-bottom: 4px; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.warn { color: var(--warning); }

/* ---------- 后台版面 ---------- */

.admin-body { background: var(--bg); }
.admin-header {
  background: #111827;
  color: #e5e7eb;
}
.admin-header-inner {
  max-width: 1240px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; min-height: 56px; gap: 4px;
}
.admin-header .brand { color: #fff; }
.admin-header .brand:hover { color: #c7d2fe; }
.admin-nav { display: flex; flex-wrap: wrap; align-items: center; }
.admin-nav a {
  color: #d1d5db; margin-left: 4px;
  padding: 6px 12px; border-radius: 8px;
}
.admin-nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; text-decoration: none; }
.admin-nav a.active { background: var(--primary); color: #fff; }
.admin-nav .nav-logout { color: #fca5a5; }
.nav-logout-form { display: inline; margin: 0; padding: 0; }
.admin-nav button.nav-logout {
  background: none; border: none; cursor: pointer; font: inherit;
  color: #fca5a5; margin-left: 4px; padding: 6px 12px; border-radius: 8px;
}
.admin-nav button.nav-logout:hover { background: rgba(255, 255, 255, .1); color: #fff; }

.admin-main {
  max-width: 1240px; margin: 0 auto;
  padding: 24px 16px 48px;
}
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin-bottom: 18px;
}
.page-head h1 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* 筛选列 */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 16px;
}
.filter-bar select, .filter-bar input { width: auto; }

/* 分页 */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .88rem;
}
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }

/* 登录页 */
.login-wrap {
  max-width: 380px; margin: 9vh auto 0; padding: 0 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { text-align: center; margin-bottom: 20px; }

/* 窄版container（购买页、订单页） */
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }

/* ---------- 响应式 ---------- */

/* ---------- 商品图片 ---------- */

.product-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
  margin-bottom: 4px;
}
/* 旧版浏览器没有 aspect-ratio 时的保底 */
@supports not (aspect-ratio: 4 / 3) {
  .product-thumb { height: 180px; }
}

.product-detail-image {
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  object-fit: cover;
  margin-bottom: 16px;
}

/* 后台列表缩略图 */
.thumb {
  width: 56px; height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: block;
}

/* ---------- 图文介绍呈现 ---------- */

.rich-content { line-height: 1.75; word-break: break-word; }
.rich-content > *:first-child { margin-top: 0; }
.rich-content > *:last-child { margin-bottom: 0; }
.rich-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 10px 0;
  display: block;
}
.rich-content h2, .rich-content h3, .rich-content h4 { margin: 1.2em 0 .5em; }
.rich-content p { margin: 0 0 1em; }
.rich-content ul, .rich-content ol { margin: 0 0 1em; padding-left: 1.6em; }
.rich-content li { margin-bottom: .35em; }
.rich-content blockquote {
  margin: 1em 0; padding: 8px 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.rich-content table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.rich-content th, .rich-content td { border: 1px solid var(--border); padding: 8px 10px; }
.rich-content pre {
  background: var(--bg); padding: 12px; border-radius: 8px;
  overflow-x: auto; font-size: .9em;
}
.rich-content code { font-family: Consolas, "Courier New", monospace; }
.rich-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }

/* ---------- 金额明细 ---------- */

.price-breakdown {
  list-style: none; margin: 0 0 16px; padding: 12px 14px;
  background: var(--bg); border-radius: 8px;
}
.price-breakdown li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 5px 0;
}
.price-breakdown li.total {
  border-top: 1px solid var(--border);
  margin-top: 6px; padding-top: 10px;
  font-weight: 700; font-size: 1.05rem;
}
.price-breakdown li.total span:last-child { color: var(--primary); }
.fee-note { color: var(--muted); font-size: .85rem; }

/* ---------- 订单解锁（邮箱 + 查询密码） ---------- */

.unlock-card { max-width: 460px; margin: 0 auto; }
.unlock-card .form-hint { margin-bottom: 12px; }

/* ---------- 后台：图片上传 ---------- */

.image-uploader {
  display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
}
.image-preview {
  width: 160px; height: 120px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.uploader-fields { flex: 1; min-width: 240px; }

/* ---------- 后台：批量导入进度 ---------- */

.import-progress { margin-top: 14px; }

.progress-track {
  height: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 999px;
  transition: width .2s ease;
}
.progress-text {
  margin-top: 8px;
  font-size: .88rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress-text.ok  { color: var(--success); }
.progress-text.err { color: var(--danger); }

/* ---------- 后台：图文介绍编辑器 ---------- */

.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px; border: 1px solid var(--border);
  border-bottom: none; border-radius: 8px 8px 0 0;
  background: var(--bg);
}
.editor-toolbar button {
  font: inherit; font-size: .85rem;
  padding: 4px 10px; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
}
.editor-toolbar button:hover { border-color: var(--primary); color: var(--primary); }
.editor-area {
  border-radius: 0 0 8px 8px;
  min-height: 240px;
  font-family: Consolas, "Courier New", monospace;
  font-size: .88rem;
}
.editor-preview {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-top: 10px;
  background: var(--surface);
}
.editor-preview-label {
  font-size: .82rem; color: var(--muted); margin-bottom: 8px;
}
.upload-status { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.upload-status.ok { color: var(--success); }
.upload-status.err { color: var(--danger); }

/* ---------- 响应式 ---------- */

@media (max-width: 640px) {
  .header-inner { flex-direction: column; height: auto; padding: 10px 0; gap: 4px; }
  .data-table { font-size: .82rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .image-uploader { flex-direction: column; }
}
