:root {
  --primary: #1677ff;
  --primary-dark: #0958d9;
  --primary-light: #e8f2ff;
  --bg: #f2f6ff;
  --ink: #1c2b3a;
  --muted: #7a8bb0;
  --line: #e6edf5;
  --card: #ffffff;
  --danger: #d4380d;
  --success: #1a9c53;
}

* { box-sizing: border-box; }
/* 关键：确保 hidden 属性优先级高于 .admin-app{display:flex} 等布局规则 */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.label { font-size: 13px; font-weight: 600; color: #566e86; }
input, select, textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid #d7e3ef; border-radius: 9px;
  background: #fbfdff; color: var(--ink);
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.7; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,119,255,.14); }
select { cursor: pointer; }

.btn {
  appearance: none; cursor: pointer; font-family: inherit;
  padding: 10px 18px; border-radius: 9px; font-size: 14px; font-weight: 600;
  border: 1px solid #d5e2ef; background: #fff; color: #2c5173;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  text-decoration: none; transition: .16s;
}
.btn:hover { background: #f2f8ff; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary {
  background: linear-gradient(135deg, #3f9bff, #1677ff);
  border-color: transparent; color: #fff;
  box-shadow: 0 5px 14px rgba(22, 119, 255, .22);
}
.btn-primary:hover { background: linear-gradient(135deg, #2f8af0, #0958d9); }
.btn-danger { color: var(--danger); border-color: #ffccc7; }
.btn-danger:hover { background: #fff2f0; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; height: 46px; font-size: 15px; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; }
.link:hover { text-decoration: underline; }

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #eaf2ff 0%, #f2f6ff 45%, #eef4ff 100%);
}
.login-box {
  width: 100%; max-width: 380px; background: #fff;
  border: 1px solid var(--line); border-radius: 18px;
  padding: 34px 28px 26px; text-align: center;
  box-shadow: 0 16px 40px rgba(35, 78, 125, .1);
}
.login-logo {
  width: 58px; height: 58px; margin: 0 auto 14px;
  border-radius: 16px; background: linear-gradient(135deg, #3f9bff, #1677ff);
  color: #fff; display: grid; place-items: center;
  font-size: 26px; font-weight: 800;
  box-shadow: 0 8px 18px rgba(22, 119, 255, .3);
}
.login-box h1 { margin: 0; font-size: 22px; font-weight: 800; }
.login-sub { margin: 6px 0 26px; color: var(--muted); font-size: 13px; }
.login-box .field { text-align: left; margin-bottom: 16px; }
.login-error {
  margin: 14px 0 0; color: var(--danger); font-size: 13px; font-weight: 600;
  background: #fff2e8; border: 1px solid #ffd8bf; border-radius: 9px; padding: 10px 12px;
}
.back-home { display: inline-block; margin-top: 20px; color: var(--muted); font-size: 13px; text-decoration: none; }
.back-home:hover { color: var(--primary); }

/* ---------- 后台布局 ---------- */
.admin-app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: none; background: #fff;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.side-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 18px; border-bottom: 1px solid var(--line);
}
.side-logo {
  width: 40px; height: 40px; flex: none; border-radius: 11px;
  background: linear-gradient(135deg, #3f9bff, #1677ff); color: #fff;
  display: grid; place-items: center; font-size: 18px; font-weight: 800;
}
.side-brand b { display: block; font-size: 14px; }
.side-brand span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.side-nav { flex: 1; padding: 14px 10px; }
.nav-item {
  appearance: none; width: 100%; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px; margin-bottom: 4px;
  border: none; border-radius: 10px; background: transparent;
  color: #566e86; font-size: 14px; font-weight: 600; text-align: left;
  transition: .15s;
}
.nav-item i { font-style: normal; width: 20px; text-align: center; font-size: 16px; color: #9db1d8; }
.nav-item:hover { background: #f4f8ff; }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item.active i { color: var(--primary); }
.side-logout {
  appearance: none; cursor: pointer; font-family: inherit;
  margin: 0 10px 16px; padding: 11px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: #7a8bb0;
  font-size: 13px; font-weight: 600;
}
.side-logout:hover { background: #fff2f0; color: var(--danger); border-color: #ffccc7; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main-header {
  height: 62px; flex: none; background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding: 0 26px; position: sticky; top: 0; z-index: 5;
}
.main-header h2 { margin: 0; font-size: 17px; font-weight: 700; flex: 1; }
.header-user {
  font-size: 12.5px; color: #566e86; font-weight: 600;
  background: var(--primary-light); color: var(--primary);
  padding: 6px 12px; border-radius: 20px;
}
.menu-btn {
  display: none; appearance: none; border: none; background: none;
  font-size: 22px; cursor: pointer; color: var(--ink); padding: 4px 8px;
}
.main-body { padding: 22px 26px 40px; flex: 1; }
.mobile-mask { display: none; }

/* ---------- 视图 ---------- */
.view-panel { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.stat-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; display: flex; align-items: center; gap: 14px;
  box-shadow: 0 4px 14px rgba(35, 78, 125, .04);
}
.stat-icon {
  width: 46px; height: 46px; flex: none; border-radius: 12px;
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: #e6f7ee; color: var(--success); }
.stat-icon.orange { background: #fff4e5; color: #d48806; }
.stat-icon.purple { background: #f3eefe; color: #722ed1; }
.stat-card span { display: block; font-size: 12.5px; color: var(--muted); }
.stat-card b { display: block; font-size: 24px; margin-top: 3px; }

.panel {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px 20px; margin-bottom: 18px;
  box-shadow: 0 4px 14px rgba(35, 78, 125, .04);
}
.panel.narrow { max-width: 460px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }

.quick-gen { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 12px; align-items: end; }
.quick-gen .btn { height: 42px; }
.gen-result {
  margin-top: 16px; background: #f6fbff; border: 1px dashed #8fc0f7;
  border-radius: 10px; padding: 14px;
}
.gen-result-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13.5px; font-weight: 600; color: #2c5173; }
.gen-result-head b { color: var(--primary); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 560px; }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid #eef2f7; white-space: nowrap; }
.table th { color: #7a8bb0; font-weight: 600; font-size: 12px; background: #fafcff; }
.table tbody tr:hover { background: #fafcff; }
.table .code-cell { font-family: ui-monospace, Consolas, monospace; font-weight: 700; color: var(--primary); letter-spacing: .3px; }
.table .ops { display: flex; gap: 6px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge.active { background: #e6f7ee; color: var(--success); }
.badge.expired { background: #fff4e5; color: #d48806; }
.badge.disabled { background: #f0f2f5; color: #8c96a6; }
.badge.used { background: #f0e8ff; color: #722ed1; }
.empty { text-align: center; color: #9aabc4; font-size: 13px; padding: 30px 10px; }

.filter-row { display: flex; gap: 10px; margin-bottom: 14px; }
.filter-row input { flex: 1; }
.filter-row select { width: 140px; flex: none; }
.head-search { width: 260px; height: 38px; }

/* ---------- 设置 ---------- */
.settings-msg { margin: 14px 0 0; font-size: 13px; font-weight: 600; }
.settings-msg.ok { color: var(--success); }
.settings-msg.err { color: var(--danger); }
.howto { margin: 0; padding-left: 20px; color: #60768c; line-height: 2; font-size: 13px; }
.howto code { background: #f2f6ff; color: var(--primary); padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #1c2b3a; color: #fff; padding: 11px 20px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; z-index: 99;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.err { background: #cf3a2e; }

/* ---------- 响应式 ---------- */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-gen { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 20;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: 6px 0 24px rgba(0,0,0,.1);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-mask.show { display: block; position: fixed; inset: 0; background: rgba(20,35,60,.35); z-index: 15; }
  .menu-btn { display: block; }
  .main-header { padding: 0 16px; }
  .main-body { padding: 16px 14px 30px; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; gap: 10px; }
  .stat-icon { width: 38px; height: 38px; font-size: 17px; }
  .stat-card b { font-size: 20px; }
  .quick-gen { grid-template-columns: 1fr; }
  .filter-row { flex-direction: column; }
  .filter-row select { width: 100%; }
  .head-search { width: 100%; }
  .panel-head { flex-wrap: wrap; }
}
