:root {
  --wx-green: #07c160;
  --wx-green-d: #06a350;
  --wx-green-l: #e8f8ef;
  --bg: #f2f6f4;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #8a8a8a;
  --line: #ededed;
  --danger: #fa5151;
  --warn: #ffc300;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
/* 点击按钮时不再闪现浏览器默认高亮块（安卓/微信等点按后的蓝色半透明层）；键盘 Tab 聚焦环仍保留 */
button:focus:not(:focus-visible), .btn:focus:not(:focus-visible), .btn-ghost:focus:not(:focus-visible), .tab:focus:not(:focus-visible), a:focus:not(:focus-visible) { outline: none; }
/* 预留滚动条空间，避免切换 tab 时滚动条出现/消失导致整页左右跳动（表现为"晃动/居中"） */
html { overflow-y: auto; scrollbar-gutter: stable; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--wx-green); text-decoration: none; }

/* ---------- 通用卡片 ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 20px; }
.page { min-height: 100vh; display: flex; flex-direction: column; }
.center-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }

/* ---------- 顶栏 ---------- */
.topbar {
  background: var(--wx-green);
  color: #fff;
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 10px rgba(7, 193, 96, 0.25);
}
.topbar .brand { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.topbar .brand .dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; display: inline-block; }
.topbar .who { font-size: 14px; opacity: 0.92; display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
@media (max-width: 640px) {
  /* 手机端：brand 隐藏，整条顶栏只保留右上角的「名字（账号） + 退出按钮」 */
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding: 10px 14px; justify-content: flex-end; }
  .topbar .brand { display: none; }
  .topbar .who { font-size: 12px; gap: 8px; }
  .topbar .who #who { max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.btn-ghost { background: rgba(255,255,255,0.18); color:#fff; border:none; border-radius: 20px; padding: 6px 14px; font-size: 13px; }
.btn-ghost:hover { background: rgba(255,255,255,0.3); }

/* ---------- 按钮 ---------- */
.btn {
  background: var(--wx-green); color: #fff; border: none; border-radius: 12px;
  padding: 12px 18px; font-size: 15px; font-weight: 500; transition: .15s; width: 100%;
}
.btn:hover { background: var(--wx-green-d); }
.btn:disabled { background: #b9e6cd; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; width: auto; border-radius: 10px; }
.btn-line { background: #fff; color: var(--wx-green); border: 1px solid var(--wx-green); }
.btn-line:hover { background: var(--wx-green-l); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #e23b3b; }
.btn-warn { background: var(--warn); color: #5a4500; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 15px; background: #fafafa; transition: .15s;
}
.input:focus { outline: none; border-color: var(--wx-green); background: #fff; }
select.input { appearance: none; }
.input-sm { padding: 6px 8px; font-size: 13px; width: auto; border-radius: 10px; }

/* ---------- 搜索行（输入 + 搜索/全部按钮，适配无搜索键的手机输入法） ---------- */
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row .input { flex: 1; min-width: 0; }
.search-row .btn { flex-shrink: 0; }
@media (max-width: 640px) {
  .search-row { flex-wrap: nowrap; }
  .search-row .btn { padding: 7px 10px; }
}

/* ---------- 登录框 ---------- */
.login-card { width: 360px; max-width: 100%; text-align: center; }
/* 登录页整体放在页面中上位置（水平居中，距顶部一段距离，不再垂直居中） */
.login-page { justify-content: flex-start; padding-top: 13vh; }

/* 登录页 logo：位于卡片上方，独立于登录卡片之外 */
.login-logo {
  width: 112px; height: auto;
  margin: 0 0 18px; display: flex; align-items: center; justify-content: center;
}
.login-logo img { width: 100%; height: auto; display: block; }
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 24px; }

/* 登录页账号/密码水平排列 */
.login-field { display: flex; align-items: center; gap: 10px; }
.login-field label {
  width: 42px; text-align: right; margin-bottom: 0;
  color: var(--text); font-size: 14px;
}
.login-field .input { flex: 1; }
.msg { font-size: 13px; padding: 9px 12px; border-radius: 10px; margin-bottom: 14px; display: none; }
.msg.err { background: #fdeaea; color: #d33; display: block; }
.msg.ok { background: var(--wx-green-l); color: var(--wx-green-d); display: block; }
.msg.warn { background: #fff8e1; color: #9a7b00; display: block; }

/* ---------- 防刷蜜罐字段（对真人不可见，自动化脚本填了即被拦截） ---------- */
.hp-trap {
  position: absolute; left: -9999px; width: 1px; height: 1px;
  overflow: hidden; opacity: 0; pointer-events: none;
}

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 9px 16px; border-radius: 20px; background: #fff; border: 1px solid var(--line);
  font-size: 14px; color: var(--muted); cursor: pointer;
}
.tab.active { background: var(--wx-green); color: #fff; border-color: var(--wx-green); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- 管理后台：左侧竖排菜单 + 右侧内容 ---------- */
.admin-layout { display: flex; align-items: flex-start; gap: 20px; }
.admin-sidebar { width: 184px; flex-shrink: 0; position: sticky; top: 20px; }
.side-menu {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px;
}
.admin-sidebar .tab {
  padding: 11px 14px; border-radius: 12px; background: transparent; border: 1px solid transparent;
  font-size: 14px; color: var(--muted); cursor: pointer; text-align: left; width: 100%;
}
.admin-sidebar .tab:hover { background: var(--wx-green-l); color: var(--wx-green-d); }
.admin-sidebar .tab.active { background: var(--wx-green); color: #fff; border-color: var(--wx-green); }
.admin-sidebar .tab.active:hover { background: var(--wx-green); color: #fff; }
.admin-main { flex: 1; min-width: 0; }

/* ---------- 统计卡 ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: linear-gradient(135deg, var(--wx-green) 0%, #0bbf6a 100%); color: #fff;
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat .n { font-size: 26px; font-weight: 600; }
.stat .l { font-size: 13px; opacity: .9; margin-top: 2px; }
.stat.alt { background: #fff; color: var(--text); }
.stat.alt .n { color: var(--wx-green-d); }

/* ---------- 列表/表格 ---------- */
.panel-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.sec-divider { height: 1px; background: var(--line); margin: 20px 0; }
.list { display: flex; flex-direction: column; gap: 12px; }
.order-item {
  background: #fff; border-radius: 14px; padding: 16px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.order-main { min-width: 0; }
.order-coupon { font-size: 16px; font-weight: 600; }
.order-meta { font-size: 13px; color: var(--muted); margin-top: 4px; word-break: break-all; }
.order-right { flex-shrink: 0; text-align: right; }
.badge { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 20px; }
.badge.pending { background: #fff8e1; color: #9a7b00; }
.badge.redeemed { background: var(--wx-green-l); color: var(--wx-green-d); }
.badge.revoked { background: #f0f0f0; color: #999; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }

/* 表格横向滚动容器：多列表格在手机端只让表格内部滚动，不撑破整页 */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.tbl th { color: var(--muted); font-weight: 500; background: #fafafa; }
table.tbl tr:hover td { background: #fcfdfc; }

/* ---------- 导入区 ---------- */
.upload-box {
  border: 2px dashed var(--line); border-radius: 14px; padding: 28px; text-align: center;
  color: var(--muted); cursor: pointer; transition: .15s; margin-bottom: 16px;
}
.upload-box:hover { border-color: var(--wx-green); color: var(--wx-green-d); background: var(--wx-green-l); }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 14px 0; }
.result-box { background: var(--wx-green-l); border-radius: 12px; padding: 14px; font-size: 13px; margin-top: 14px; }
.result-box .warn-line { color: #9a7b00; }
.muted { color: var(--muted); font-size: 13px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 16px; }
  /* 卡片条目：上下结构；order-main 与 order-right 均整宽，底部用虚线分隔 */
  .order-item { flex-direction: column; align-items: stretch; gap: 4px; }
  .order-right {
    width: 100%;
    text-align: left;
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
    display: flex;
    align-items: center;
    min-height: 38px;
  }
  /* mobile 下 badge 升级为与「核销」按钮同高度同尺寸的胶囊，保证卡片底部大小统一 */
  .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    height: 34px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 13px;
  }
  /* mobile 下「核销」按钮与 badge 同高，卡片底部对齐 */
  .order-right .btn-sm { min-height: 34px; }
}
@media (max-width: 768px) {
  .admin-layout { flex-direction: column; gap: 14px; align-items: stretch; }
  .admin-sidebar { width: 100%; position: static; }
  .admin-main { width: 100%; min-width: 0; }
  .side-menu { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .admin-sidebar .tab { flex: 1 1 auto; min-width: 88px; text-align: center; width: auto; }

  /* 数据看板：手机端统计卡统一为白底卡片+绿色左边框，与订单/核销记录卡风格一致 */
  .stats-grid { grid-template-columns: 1fr; }
  .stat, .stat.alt {
    background: #fff; color: var(--text);
    border: 1px solid var(--line);
    border-left: 4px solid var(--wx-green);
    border-radius: 14px;
    padding: 16px 18px;
    box-shadow: 0 4px 14px rgba(0,0,0,.06);
    width: 100%; min-width: 0;
  }
  .stat .n, .stat.alt .n { color: var(--wx-green-d); }
  .stat .l, .stat.alt .l { color: var(--muted); opacity: 1; }

  /* 管理员表格：手机端把每行折成卡片，字段名用 data-label 显示，取消横向滚动 */
  .table-wrap { overflow-x: visible; }
  table.tbl { min-width: 0; }
  /* 模板表头未用 <thead> 包裹，首行即表头，直接隐藏首行 */
  table.tbl tr:first-child { display: none; }
  table.tbl, table.tbl tbody, table.tbl tr { display: block; width: 100%; }
  table.tbl tbody tr {
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    padding: 4px 0; margin-bottom: 12px;
  }
  table.tbl tbody td {
    border: none; border-bottom: 1px solid #f4f4f4;
    padding: 9px 14px; white-space: normal;
    /* grid 让字段名在左、值在固定宽列里，超长内容强制换行，不会顶出卡片 */
    display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px;
    overflow-wrap: anywhere; word-break: break-all;
  }
  table.tbl tbody td:last-child { border-bottom: none; }
  table.tbl tbody td::before {
    content: attr(data-label);
    color: var(--muted); font-size: 12px; font-weight: 500;
    text-align: left; white-space: nowrap;
  }
  /* 操作列在手机端整行显示，按钮更易点 */
  table.tbl tbody td.ops { display: block; text-align: left; }
  table.tbl tbody td.ops::before { display: block; margin-bottom: 6px; }
  table.tbl tbody td.ops .input,
  table.tbl tbody td.ops .btn { width: auto; }
}

/* ---------- 核销弹窗（B 风格：微信绿 + 圆角卡片）---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: none; align-items: center; justify-content: center;
  padding: 20px; z-index: 100; animation: maskIn .18s ease;
}
.modal {
  width: 340px; max-width: 100%; background: #fff; border-radius: var(--radius);
  padding: 28px 24px 22px; box-shadow: 0 16px 48px rgba(0, 0, 0, .22);
  animation: modalIn .24s cubic-bezier(.2, .85, .3, 1.08); text-align: center;
}
.modal-icon {
  width: 58px; height: 58px; border-radius: 50%; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #fff; font-weight: 700;
}
.modal-icon.success { background: var(--wx-green); }
.modal-icon.error { background: var(--danger); }
.modal-icon.confirm { background: var(--wx-green); }
.modal-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 14px; }
.modal-body { font-size: 14px; color: #555; line-height: 1.6; margin-bottom: 20px; }
.modal-body .kv {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 7px 2px; border-bottom: 1px dashed var(--line); text-align: left;
}
.modal-body .kv:last-child { border-bottom: none; }
.modal-body .kv span { color: var(--muted); flex-shrink: 0; }
.modal-body .kv b { color: var(--text); font-weight: 600; text-align: right; word-break: break-all; }
.modal-actions { display: flex; gap: 12px; }
.modal-actions .btn { width: auto; flex: 1; }
@keyframes maskIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { transform: translateY(16px) scale(.95); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 分页栏（每页 20/50/100 + 上/下页 + 共 X 条）---------- */
.pager-wrap { margin-top: 16px; }
.pager { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pager-info { font-size: 13px; color: var(--muted); }
.pager-size { width: auto; padding: 6px 10px; }
.pager-btn { width: auto; }
@media (max-width: 640px) {
  .pager { gap: 8px; }
  .pager-info { width: 100%; }
}
