:root {
  --bg: #F5F6FA;
  --card: #FFFFFF;
  --primary: #2B5AED;
  --green: #16A34A;
  --red: #DC2626;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5E7EB;
  --dark: #111827;
  --side: #1E293B;
  --side-text: #CBD5E1;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.break-all { word-break: break-all; }
.right { text-align: right; }

/* ---------------------------------------------------------------- 框架 */
.admin-layout { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 220px;
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.side-logo {
  height: 64px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.side-logo strong { color: #fff; font-size: 16px; }
.side-logo small { color: #94A3B8; font-size: 11px; margin-top: 2px; }
.side-nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-group {
  padding: 16px 12px 8px;
  font-size: 11px;
  color: #64748B;
}
.nav-item {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  color: var(--side-text);
  font-size: 13px;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active {
  background: rgba(43, 90, 237, .24);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-logout-form { margin: 0; display: block; }
.nav-item-btn {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  line-height: normal;
}
.nav-item-btn:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-bottom {
  padding: 12px 8px 16px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.side-link {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  text-align: left;
  color: var(--side-text);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.side-link:hover { color: #fff; }
.side-button { font-family: inherit; }

.main { flex: 1; min-width: 0; margin-left: 220px; height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.admin-topbar h1 { font-size: 18px; font-weight: 700; }
.admin-name { margin-left: auto; font-size: 13px; color: var(--muted); }
.menu-btn {
  display: none;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
}
.admin-content { padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 16px; min-height: 0; }

/* ---------------------------------------------------------------- 通用 */
.flash-list { display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 12px; border-radius: 10px; font-size: 13px; }
.flash-success { background: #ECFDF5; color: #166534; }
.flash-error { background: #FEF2F2; color: #991B1B; }
.flash-info { background: #EFF6FF; color: #1E40AF; }
.top-link { color: var(--muted); font-size: 13px; text-decoration: none; }
.top-link:hover { color: var(--primary); }
.inline-form { display: inline; }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-height: 0;
}
.panel:has(.table) {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.panel:has(.table) > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin: 0;
}
.panel:has(.table) .table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.admin-content:not(:has(.table)) .panel {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.cards-gen-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.cards-gen-row .panel { margin-bottom: 0; }
.btn-copy-mini {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.btn-copy-mini:hover { color: var(--primary); border-color: var(--primary); }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2 { font-size: 15px; font-weight: 700; }
.title-inline { display: inline-flex; align-items: center; gap: 4px; }

.btn {
  height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--card); border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { background: var(--border); color: #9CA3AF; cursor: not-allowed; }

.btn-sm {
  height: 32px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger-text { color: var(--red); }
.btn-danger-text:hover { border-color: var(--red); color: var(--red); }
.btn-icon {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
textarea { padding: 12px; line-height: 1.6; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(43, 90, 237, .12);
}
.field-check { display: flex; flex-direction: column; }
.check-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.check-label input { width: 16px; height: 16px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; margin-top: 8px; }
.form-row-between { margin-top: 12px; }
.form-actions { display: flex; align-items: flex-end; }
.form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}
.form-grid .field { margin-bottom: 0; }
.inline-form-row { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.field-inline { width: 120px; margin-bottom: 0; }

/* ---------------------------------------------------------------- 统计卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1.2vw, 16px);
}
.stat-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vw, 12px);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(8px, 1.1vw, 16px);
  color: inherit;
  text-decoration: none;
  transition: box-shadow .18s ease, transform .18s ease;
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(17, 24, 39, .10);
}
.stat-arrow {
  position: absolute;
  top: 6px;
  right: 9px;
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
}
.stat-icon {
  width: clamp(26px, 3.2vw, 40px);
  height: clamp(26px, 3.2vw, 40px);
  border-radius: clamp(6px, .8vw, 10px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(10px, 1vw, 13px);
  font-weight: 700;
  flex-shrink: 0;
}
.stat-blue { background: #EFF6FF; color: var(--primary); }
.stat-green { background: #ECFDF5; color: var(--green); }
.stat-orange { background: #FFF7ED; color: #C2410C; }
.stat-purple { background: #F5F3FF; color: #7C3AED; }
.stat-label {
  font-size: clamp(10px, .9vw, 12px);
  color: var(--muted);
  white-space: nowrap;
}
.stat-value {
  font-size: clamp(14px, 1.7vw, 26px);
  font-weight: 700;
  line-height: 1.2;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 表格 */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 12px;
  background: #F9FAFB;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid #F3F4F6;
  font-size: 13px;
  vertical-align: middle;
  text-align: center;
}
.table td.right, .table th.right { text-align: center; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FAFAFB; }
.actions { white-space: nowrap; }
.actions > * { margin-left: 4px; }
.check-col { width: 36px; text-align: center; }
.check-col input { width: 16px; height: 16px; }
.card-code { letter-spacing: .5px; }
.amount-negative { color: var(--red); }
.amount-positive { color: var(--green); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}
.pill-on { background: #ECFDF5; color: #166534; }
.pill-off { background: #F3F4F6; color: var(--muted); }
.pill-take { background: #EFF6FF; color: var(--primary); }
.pill-recharge { background: #ECFDF5; color: #166534; }
.pill-adjust { background: #FFF7ED; color: #C2410C; }

.filter-tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-divider { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.filter-tab {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
}
.filter-tab.active { background: #EFF6FF; color: var(--primary); font-weight: 600; }
.filter-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filter-form select, .filter-form input { min-height: 36px; font-size: 13px; width: auto; }
.search-form { display: flex; align-items: center; gap: 8px; }
.search-form input { min-height: 36px; width: 180px; font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }
.pager-btn {
  height: 34px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
}
.pager-btn.disabled { color: #9CA3AF; background: #F9FAFB; }
.pager-info { font-size: 13px; color: var(--muted); }

.empty-state { text-align: center; padding: 32px 16px; }
.empty-state.small { padding: 24px 16px; }
.empty-title { font-size: 15px; font-weight: 700; }
.empty-desc { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

/* ---------------------------------------------------------------- 导入 */
.import-banner {
  background: #EFF6FF;
  color: var(--primary);
  border: 1px solid #DBEAFE;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  margin-bottom: 12px;
}
.import-banner strong { font-size: 17px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.result-stat { border-radius: 10px; padding: 12px; }
.result-stat span { font-size: 12px; }
.result-stat strong { display: block; font-size: 24px; margin-top: 4px; }
.result-stat.stat-green { background: #ECFDF5; color: #166534; }
.result-stat.stat-orange { background: #FFF7ED; color: #C2410C; }
.result-stat.stat-red { background: #FEF2F2; color: #991B1B; }

/* ---------------------------------------------------------------- 弹窗 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .45);
  z-index: 110;
}
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 480px;
  max-width: calc(100% - 32px);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
  padding: 16px;
  z-index: 120;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; }
.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.temp-password {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #F3F4F6;
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
}
.temp-password .mono { font-size: 18px; font-weight: 700; letter-spacing: 1px; }

/* 订单行可点击 */
.order-row { cursor: pointer; }
.order-row:hover { background: #F5F7FF; }

/* 订单详情弹窗 */
.order-detail { display: flex; flex-direction: column; gap: 12px; }
.order-detail-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 14px; }
.order-detail-row span { color: var(--muted); flex-shrink: 0; }
.order-detail-row strong { font-weight: 600; text-align: right; word-break: break-all; }

/* 订单详情内的取码链接 */
.order-link-box {
  margin-top: 16px;
  padding: 12px;
  background: #F5F7FF;
  border: 1px solid #E0E7FF;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.order-link-head { font-size: 12px; color: var(--muted); }
.order-link-url {
  font-size: 12px;
  line-height: 1.5;
  color: #2563EB;
  word-break: break-all;
  text-decoration: none;
}
.order-link-url:hover { text-decoration: underline; }
.order-link-btn { align-self: flex-start; }

/* 后台取码结果 */
.sms-result {
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed #C7D2FE;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sms-result[hidden] { display: none; }
.sms-code { font-size: 26px; font-weight: 800; letter-spacing: 4px; color: #1D4ED8; }
.sms-body { font-size: 12px; color: var(--muted); line-height: 1.6; word-break: break-all; max-height: 96px; overflow-y: auto; }
.sms-tip { font-size: 13px; color: #B91C1C; }

.notice {
  background: #FEF3C7;
  color: #92400E;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.notice-tag {
  display: inline-block;
  padding: 1px 6px;
  margin-right: 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .08);
  color: #92400E;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
}
.contact-box {
  background: #F9FAFB;
  border: 1px dashed #E5E7EB;
  border-radius: 10px;
  padding: 12px;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.notice-warn { margin-bottom: 16px; }
.preview-block { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }
.preview-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }

/* ---------------------------------------------------------------- 公告与联系 */
.notice-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
}
.notice-layout > .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.notice-form { display: flex; flex-direction: column; gap: 0; flex: 1; }
.field-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field-label > .muted { font-size: 11px; }
.preview-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.preview-section { display: flex; flex-direction: column; gap: 8px; }

/* ---------------------------------------------------------------- 登录 */
html:has(body.auth-body), body.auth-body { overflow: auto; }
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.auth-title { font-size: 22px; font-weight: 700; text-align: center; }
.auth-sub { font-size: 13px; color: var(--muted); text-align: center; margin: 4px 0 20px; }
.auth-form { margin-top: 4px; }
.pwd-wrap { position: relative; display: block; }
.pwd-wrap input { padding-right: 56px; }
.pwd-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  height: 28px;
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.auth-foot { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.auth-foot-row { display: flex; align-items: center; justify-content: space-between; }
.auth-foot .link-btn, .link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
}

/* ---------------------------------------------------------------- Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(17, 24, 39, .94);
  color: #fff;
  font-size: 13px;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  text-align: center;
}

/* ---------------------------------------------------------------- 货架图标上传 */
.shelf-icon-img {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #f4f5f7;
}
.shelf-icon-emoji {
  font-size: 22px;
  vertical-align: middle;
}
.icon-uploader {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}
.icon-preview {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f4f5f7, #e9ebef);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.icon-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.icon-placeholder {
  font-size: 26px;
}
.icon-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------------------------------------------------------------- 公告类型与状态 */
.n-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.n-type-0 { background: #FEF3C7; color: #92400E; }  /* 放单规则 黄 */
.n-type-1 { background: #FEF3C7; color: #92400E; }  /* 售后规则 黄 */
.n-type-2 { background: #DBEAFE; color: #1E40AF; }  /* 活动通知 蓝 */
.n-type-3 { background: #FEE2E2; color: #B91C1C; }  /* 紧急通知 红 */
.n-visible { color: #166534; font-size: 12px; font-weight: 600; }
.n-top { color: #B45309; font-size: 12px; font-weight: 600; }
.n-hidden { color: var(--muted); font-size: 12px; font-weight: 600; }
.notice-content-cell {
  max-width: 360px;
  word-break: break-word;
  line-height: 1.5;
}
.notice-tpl-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 4px;
}
.notice-tpl-row .muted { font-size: 11px; }

@media (max-width: 1200px) {
  .stat-grid { gap: 10px; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .admin-topbar { padding: 0 16px; }
  .admin-content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .form-actions { grid-column: 1 / -1; }
  .cards-gen-row { grid-template-columns: 1fr; }
  .notice-layout { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .stat-grid { gap: 6px; }
  .stat-arrow { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .filter-form, .search-form { width: 100%; }
  .search-form input { flex: 1; width: auto; }
  .result-stats { grid-template-columns: 1fr; }
  .admin-name { display: none; }
}
