/* ==========================================================================
   发卡商城 · 后台管理样式（Apple 风格 v2，2026-09-15）
   设计三原则：Clarity（内容优先）/ Deference（界面退让）/ Depth（层次感）
   - 单一强调色 #0071e3，无渐变、无彩色装饰块
   - 系统字体栈 SF Pro / PingFang SC，字重仅 400 / 500 / 600
   - 卡片 18px 圆角 + 极淡描边 + 柔和投影；胶囊按钮；玻璃质感侧边栏
   - 缓动统一 cubic-bezier(.25,.1,.25,1)；末尾有 reduced-motion 兜底
   - 所有旧类名 / 变量名全部保留，模板与 JS 无需改动即可生效
   ========================================================================== */

:root {
  /* 强调色（Apple 系统蓝） */
  --primary: #0071e3;
  --primary-hover: #0077ed;
  --primary-light: rgba(0, 113, 227, .10);

  /* 语义色（Apple 系统色） */
  --success: #34c759;
  --danger: #ff3b30;
  --warning: #ff9f0a;

  /* 中性阶（Apple 灰） */
  --bg: #f5f5f7;
  --panel: #ffffff;
  --glass: rgba(255, 255, 255, .72);
  --border: rgba(0, 0, 0, .08);
  --border-strong: rgba(0, 0, 0, .16);
  --hover: rgba(0, 0, 0, .035);
  --text: #1d1d1f;
  --text-sub: #6e6e73;
  --muted: #6e6e73;
  --tertiary: #86868b;

  /* 圆角 / 阴影 */
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --pill: 980px;
  --sidebar-w: 220px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow: 0 4px 24px rgba(0, 0, 0, .06);
  --shadow-lg: 0 28px 70px -20px rgba(0, 0, 0, .28);

  /* 动效 */
  --ease: cubic-bezier(.25, .1, .25, 1);
  --dur: .3s;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::selection { background: rgba(0, 113, 227, .16); }
a { color: var(--primary); }
img { max-width: 100%; }

/* 细滚动条（Apple 式） */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .18); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .32); background-clip: content-box; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--border);
  padding: 22px 14px; position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  display: flex; flex-direction: column;
}
.brand {
  font-size: 16px; font-weight: 600; letter-spacing: -.01em;
  padding: 6px 10px 22px; display: flex; align-items: center; gap: 9px;
  color: var(--text); word-break: break-word;
}
.brand .dot { width: 11px; height: 11px; border-radius: 4px; background: var(--primary); flex-shrink: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 10px; color: var(--text-sub); text-decoration: none;
  font-size: 14px; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.active { background: rgba(0, 113, 227, .12); color: #0058b8; font-weight: 600; }
.nav a svg { width: 17px; height: 17px; flex-shrink: 0; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); padding: 26px 30px 44px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -.02em; text-wrap: balance; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: 13.5px; text-wrap: pretty; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card .card-body { padding: 22px 24px; }
.card .card-body > h3 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 18px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td {
  padding: 13px 14px; text-align: left; font-size: 13px;
  border-bottom: 1px solid var(--border); vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
th {
  color: var(--muted); font-weight: 500; font-size: 12px;
  white-space: nowrap; letter-spacing: .02em;
}
thead th { border-bottom-color: rgba(0, 0, 0, .12); }
tbody tr { transition: background var(--dur) var(--ease); }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.empty { text-align: center; color: var(--muted); padding: 44px 0 !important; }
.trunc {
  display: block; max-width: 130px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 按钮（胶囊） ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 9px 18px; border-radius: var(--pill);
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  font-size: 14px; font-family: inherit; white-space: nowrap; text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform .15s var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { background: var(--hover); border-color: rgba(0, 0, 0, .26); }
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-danger { color: #b3261e; border-color: rgba(255, 59, 48, .34); }
.btn-danger:hover { background: rgba(255, 59, 48, .08); border-color: #b3261e; color: #b3261e; }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* 表格内操作按钮：Apple 式纯文字按钮（蓝色文字 + 淡底 hover）
   命中区：36px 高 + 伪元素横向外扩，≥40px 触控标准 */
td .btn {
  position: relative;
  min-height: 36px; padding: 6px 12px; font-size: 13px;
  background: transparent; border-color: transparent; color: var(--primary);
}
td .btn::after { content: ""; position: absolute; inset: 0 -6px; }
td .btn:hover { background: var(--primary-light); border-color: transparent; }
td .btn-danger { color: #b3261e; background: transparent; }
td .btn-danger:hover { background: rgba(255, 59, 48, .08); border-color: transparent; }

/* 表格操作列：flex 布局强制垂直居中。
   原因：inline-flex 按钮里图标在前的（编辑/删除）基线由 svg 底边合成，
   纯文字按钮（停用）基线是文字基线，两者不一致导致按钮上下错位。 */
td.cell-ops { display: flex; align-items: center; gap: 4px; }
td.cell-ops .btn { min-width: 68px; justify-content: center; }

/* ---------- 表单 ---------- */
.form-item { margin-bottom: 18px; }
.form-item label {
  display: block; margin-bottom: 7px; font-size: 13px;
  color: var(--text-sub); font-weight: 500;
}
.form-item label b { color: #b3261e; margin-right: 3px; font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--panel);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--tertiary); }
.input:hover, .select:hover, .textarea:hover { border-color: rgba(0, 0, 0, .24); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light);
}
.textarea { min-height: 120px; padding: 11px 14px; resize: vertical; line-height: 1.6; }
.select {
  -webkit-appearance: none; appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 12px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters .input, .filters .select { width: auto; min-width: 150px; }

/* ---------- 徽标 ---------- */
.tag {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px 11px; border-radius: var(--pill);
  font-size: 12px; font-weight: 500; line-height: 1.5; white-space: nowrap;
}
.tag-green { background: rgba(52, 199, 89, .13); color: #1a7f37; }
.tag-red { background: rgba(255, 59, 48, .11); color: #b3261e; }
.tag-gray { background: rgba(0, 0, 0, .05); color: #5f5e5a; }
.tag-blue { background: rgba(0, 113, 227, .10); color: #0058b8; }
.tag-orange { background: rgba(255, 149, 0, .14); color: #8a5600; }
.tag-purple { background: rgba(175, 82, 222, .12); color: #8e3fc0; }

/* ---------- 统计卡 ---------- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; display: flex; flex-direction: column;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: rgba(0, 0, 0, .12); }
/* hover 位移只在无入场动画冲突时生效：入场期间锁定 transform，动画结束（both 保留终态）后由 hover 接管 */
@media (prefers-reduced-motion: no-preference) {
  .stat { animation-fill-mode: backwards; }
}
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value {
  font-size: 30px; font-weight: 600; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; word-break: break-word;
}
.stat .value.danger { color: var(--danger); }
/* 仪表盘卡片入场：轻微上移淡入，逐卡延迟（reduced-motion 由文件末尾统一降级） */
@media (prefers-reduced-motion: no-preference) {
  .stat { animation: statIn .4s var(--ease) backwards; }
  .stat:nth-child(2) { animation-delay: .05s; }
  .stat:nth-child(3) { animation-delay: .1s; }
  .stat:nth-child(4) { animation-delay: .15s; }
}
@keyframes statIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stat-icon {
  width: 36px; height: 36px; border-radius: 10px; margin-bottom: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 17px; height: 17px; }
.si-blue { background: rgba(0, 113, 227, .10); color: #0071e3; }
.si-green { background: rgba(52, 199, 89, .13); color: #1a7f37; }
.si-orange { background: rgba(255, 149, 0, .14); color: #8a5600; }
.si-red { background: rgba(255, 59, 48, .11); color: #c9241c; }
.si-purple { background: rgba(175, 82, 222, .12); color: #8e3fc0; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .28);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  overflow-y: auto; padding: 40px 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--panel); border-radius: 22px; width: 560px; max-width: 100%;
  padding: 26px; margin: auto; box-shadow: var(--shadow-lg);
  animation: modalIn var(--dur) var(--ease);
}
.modal.lg { width: 760px; }
.modal h3 { margin-bottom: 20px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; text-wrap: balance; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to { opacity: 1; transform: none; }
}

/* ---------- 轻提示 ---------- */
#toast {
  position: fixed; top: 20px; left: 50%; z-index: 200; pointer-events: none;
  /* 隐藏态：整体高度 + top 偏移全部出屏（-140% 这类按自身高度算的位移在短消息时会露出底边） */
  transform: translateX(-50%) translateY(calc(-100% - 40px));
  opacity: 0;
  background: rgba(29, 29, 31, .94);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  color: #fff; padding: 12px 22px; border-radius: var(--pill);
  font-size: 14px; line-height: 1.45; text-align: center; max-width: calc(100% - 32px);
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, .45);
  transition: transform .42s var(--ease), opacity .3s var(--ease);
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.err { background: rgba(198, 40, 40, .95); }

/* ---------- 分页 ---------- */
.pagination {
  display: flex; gap: 8px; justify-content: flex-end; align-items: center;
  margin-top: 18px; color: var(--muted); font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.pagination button {
  min-width: 40px; height: 40px; padding: 0 12px;
  border-radius: var(--pill); border: 1px solid var(--border-strong);
  background: var(--panel); color: var(--text); font-size: 14px; font-family: inherit;
  cursor: pointer; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.pagination button svg { width: 15px; height: 15px; }
.pagination button:hover:not(:disabled) { background: var(--hover); border-color: rgba(0, 0, 0, .26); }
.pagination button:disabled { opacity: .35; cursor: not-allowed; }
.pagination button.on { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- 杂项 ---------- */
.muted { color: var(--muted); font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* UA 单元格（拉取记录）：点击复制，hover 显复制图标 */
.ua-cell {
  display: inline-flex; align-items: center; gap: 5px;
  cursor: copy; max-width: 100%;
  padding: 2px 4px; margin: -2px -4px; /* 扩大热区不占布局 */
  border-radius: 6px;
  transition: background var(--dur) var(--ease);
}
.ua-cell:hover { background: var(--hover); }
.ua-copy-icon {
  width: 13px; height: 13px; flex: none;
  color: var(--muted); opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.ua-cell:hover .ua-copy-icon { opacity: 1; }
.ua-cell:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) { .ua-cell, .ua-copy-icon { transition: none; } }

.pre-box {
  background: rgba(0, 0, 0, .028); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
  max-height: 280px; overflow: auto; white-space: pre-wrap; word-break: break-all;
  font-size: 12.5px; line-height: 1.7;
}

/* 按钮内联加载动画（保存中等异步操作）：用 currentColor，浅深底都可见 */
.spinner-border {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; opacity: .9; vertical-align: -2px; margin-right: 6px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 移动端自适应（≤768px） ---------- */
.menu-btn {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 20;
  width: 40px; height: 40px; padding: 0; border-radius: 12px;
  border: 1px solid var(--border); background: var(--glass);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: var(--shadow-sm); cursor: pointer;
  align-items: center; justify-content: center; color: var(--text);
}
.menu-btn svg { width: 19px; height: 19px; }
/* feather 图标：脚本加载/替换瞬间的占位，避免裸元素闪动 */
i[data-feather] { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; }
svg.feather { display: inline-block; }
.sidebar-mask { display: none; position: fixed; inset: 0; z-index: 48; background: rgba(0, 0, 0, .3); }

@media (max-width: 768px) {
  .menu-btn { display: inline-flex; }

  .sidebar {
    width: 240px; transform: translateX(-100%);
    transition: transform .28s var(--ease);
    box-shadow: 0 0 40px rgba(0, 0, 0, .14);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-mask { display: block; }

  .main { margin-left: 0; padding: 64px 14px 32px; }

  .page-head { margin-bottom: 18px; }
  .page-head h1 { font-size: 22px; }
  .page-head .sub { font-size: 13px; }

  .card .card-body { padding: 16px 14px; }
  .card { border-radius: 16px; }

  /* 统计卡：两列（跟随视口收缩，不写死列数） */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat { padding: 14px 16px; border-radius: 16px; }
  .stat .value { font-size: 22px; }
  .stat-icon { width: 32px; height: 32px; margin-bottom: 10px; }

  /* 表格横向滚动；列给最小宽度，避免内容逐列换行把行撑高 */
  th, td { padding: 11px 10px; font-size: 12px; min-width: 90px; }
  .empty { min-width: 0; }
  td .btn { min-height: 36px; }

  .filters { gap: 8px; }
  .filters .input, .filters .select { min-width: 0 !important; width: 100% !important; }
  .filters .btn { width: 100%; }
  .filters > div { width: 100%; }

  .modal-mask { padding: 16px 12px; }
  .modal, .modal.lg { width: 100%; padding: 20px 16px; border-radius: 18px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }

  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .pagination { justify-content: center; flex-wrap: wrap; }  .brand { padding-bottom: 16px; }
  .trunc { max-width: 110px; }
}

/* ---------- 动效降级（必须放在文件末尾，避免被后续规则覆盖） ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .stat { animation: none; }
  .stat:hover { transform: none; }
  .btn:active { transform: none; }
}
