/* ==========================================================================
   CardKey Console — 企业级卡密管理台
   纯静态，无任何外部依赖
   ========================================================================== */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #7b8794;
  --line: #e5e9f2;
  --line-2: #eef1f7;
  --brand: #2f6bff;
  --brand-2: #1e4fd8;
  --brand-soft: #eaf0ff;
  --ok: #0f9d58;
  --ok-soft: #e7f6ee;
  --warn: #d97706;
  --warn-soft: #fef4e6;
  --danger: #dc2626;
  --danger-soft: #fdeced;
  --side-1: #0b1220;
  --side-2: #121c2f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Inter", "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
::selection { background: #c7d7ff; }

/* ---------- 登录 ---------- */
#login {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 15% 10%, #1b3a8f 0%, transparent 60%),
    radial-gradient(700px 500px at 85% 90%, #12325e 0%, transparent 55%),
    #0a1020;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 16px;
  padding: 34px 32px 28px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .6);
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(140deg, #4d8dff, #1e4fd8);
  display: grid; place-items: center; color: #fff; font-weight: 700;
  box-shadow: 0 6px 16px -6px rgba(47, 107, 255, .9);
}
.login-brand h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.login-card h2 { font-size: 20px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-tip {
  margin-top: 18px; padding: 12px 14px; border-radius: 10px;
  background: #f7f9fd; border: 1px solid var(--line);
  font-size: 12px; color: var(--muted); line-height: 1.7;
}
.login-tip code { font-family: var(--mono); color: var(--ink-2); }

/* ---------- 布局 ---------- */
#app { display: none; height: 100%; }
#app.on { display: grid; grid-template-columns: 236px 1fr; }

.sidebar {
  background: linear-gradient(180deg, var(--side-1), var(--side-2));
  color: #cbd5e1;
  display: flex; flex-direction: column;
  padding: 18px 14px;
  gap: 6px;
  overflow: hidden;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.sb-brand .logo { width: 34px; height: 34px; border-radius: 9px; font-size: 13px; }
.sb-brand strong { color: #fff; font-size: 15px; display: block; letter-spacing: .3px; }
.sb-brand span { font-size: 11px; color: #7c8aa5; letter-spacing: .6px; text-transform: uppercase; }

.nav-group { font-size: 11px; color: #5b6b86; letter-spacing: 1px; padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px;
  color: #b6c2d6; cursor: pointer; border: 0; background: none;
  width: 100%; text-align: left; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(47, 107, 255, .28), rgba(47, 107, 255, .06));
  color: #fff;
  box-shadow: inset 2px 0 0 #4d8dff;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav-item .count {
  margin-left: auto; font-size: 11px; background: rgba(255, 255, 255, .1);
  padding: 1px 7px; border-radius: 20px; color: #dbe4f5;
}
.sb-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid rgba(255, 255, 255, .07); font-size: 11px; color: #566578; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100%; }

.topbar {
  height: 60px; flex: none;
  background: rgba(255, 255, 255, .85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
}
.topbar h2 { font-size: 15px; margin: 0; font-weight: 600; }
.topbar .crumb { color: var(--muted); font-size: 12.5px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: 8px;
  background: #f6f8fc; border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2);
}
.chip b { font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }

.view { flex: 1; overflow: auto; padding: 24px; }
.view-inner { max-width: 1360px; margin: 0 auto; }

/* ---------- 通用组件 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-hd {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 20px; border-bottom: 1px solid var(--line-2);
}
.card-hd h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card-hd .sub { color: var(--muted); font-size: 12px; }
.card-hd .right { margin-left: auto; display: flex; gap: 8px; }
.card-bd { padding: 18px 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .06s;
}
.btn:hover { background: #f7f9fc; border-color: #d7ddea; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #3d78ff, var(--brand));
  border-color: var(--brand-2); color: #fff;
  box-shadow: 0 6px 14px -8px rgba(47, 107, 255, .9);
}
.btn.primary:hover { background: linear-gradient(180deg, #4a83ff, var(--brand-2)); }
.btn.danger { color: var(--danger); border-color: #f3c9cc; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f4fa; color: var(--ink); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; height: 40px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500; }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: #a9c1ff; box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
.input::placeholder { color: #aab4c2; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; right: -28px; top: -28px;
  width: 90px; height: 90px; border-radius: 50%; background: var(--brand-soft); opacity: .55;
}
.stat .k { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 28px; font-weight: 650; letter-spacing: -.5px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.ok .v { color: var(--ok); } .stat.warn .v { color: var(--warn); } .stat.bad .v { color: var(--danger); }
.stat.ok::after { background: var(--ok-soft); }
.pulse { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(15,157,88,.55); animation: pulse 1.8s infinite; margin-right: 5px; vertical-align: 1px; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(15,157,88,0); } 100% { box-shadow: 0 0 0 0 rgba(15,157,88,0); } } .stat.warn::after { background: var(--warn-soft); } .stat.bad::after { background: var(--danger-soft); }

/* ---------- 表格 ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: 10px 14px; background: #fafbfe; border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:hover td { background: #fafcff; }
tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: .2px; }
.key-cell { display: flex; align-items: center; gap: 8px; }
.key-cell .copy { opacity: 0; transition: opacity .15s; }
tr:hover .key-cell .copy { opacity: 1; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: .35; margin-bottom: 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge.available { background: var(--ok-soft); color: #0b7a45; }
.badge.in_use { background: var(--brand-soft); color: var(--brand-2); }
.badge.expired { background: #eef1f6; color: #64748b; }
.badge.disabled { background: var(--danger-soft); color: var(--danger); }
.badge.plan { background: #f4f0ff; color: #6b46c1; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .input, .toolbar select { height: 36px; }
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 360px; }
.toolbar .search svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; color: var(--muted); }
.toolbar .search .input { padding-left: 34px; }

.pager { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--line-2); color: var(--muted); font-size: 12.5px; }
.pager .pages { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.bulkbar {
  display: none; align-items: center; gap: 10px;
  padding: 10px 16px; margin-bottom: 12px; border-radius: 10px;
  background: var(--brand-soft); border: 1px solid #cfe0ff; color: var(--brand-2); font-size: 13px;
}
.bulkbar.on { display: flex; }

/* ---------- 图表 ---------- */
.chart { display: flex; align-items: flex-end; gap: 14px; height: 150px; padding: 8px 4px 0; }
.chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.chart .bar i {
  display: block; width: 100%; max-width: 46px; border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, #6f9bff, #2f6bff); min-height: 3px;
  transition: height .4s cubic-bezier(.2, .8, .2, 1);
}
.chart .bar span { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart .bar b { font-size: 11.5px; color: var(--ink-2); font-weight: 600; }

.plan-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 13px; }
.plan-row .bar-bg { flex: 1; height: 8px; background: #eef1f7; border-radius: 20px; overflow: hidden; }
.plan-row .bar-bg i { display: block; height: 100%; border-radius: 20px; background: linear-gradient(90deg, #6f9bff, #2f6bff); }
.plan-row .n { width: 32px; text-align: right; color: var(--muted); font-size: 12px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: none; place-items: center; z-index: 80; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-mask.on { display: grid; }
.modal {
  width: 100%; max-width: 460px; background: #fff; border-radius: 14px;
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .4); overflow: hidden;
  animation: pop .15s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
.modal h3 { margin: 0; padding: 18px 20px; font-size: 15px; border-bottom: 1px solid var(--line-2); }
.modal .bd { padding: 18px 20px; font-size: 13.5px; color: var(--ink-2); }
.modal .ft { padding: 14px 20px; background: #fafbfe; border-top: 1px solid var(--line-2); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 90; }
.toast {
  min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: 10px;
  background: #fff; border: 1px solid var(--line); box-shadow: 0 12px 30px -12px rgba(15, 23, 42, .3);
  font-size: 13px; display: flex; gap: 10px; align-items: flex-start;
  animation: slide .2s ease-out;
}
@keyframes slide { from { transform: translateX(12px); opacity: 0; } }
.toast .ic { width: 18px; height: 18px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; }
.toast.ok .ic { background: var(--ok); } .toast.err .ic { background: var(--danger); } .toast.info .ic { background: var(--brand); }

/* ---------- 生成结果 ---------- */
.result-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px;
  max-height: 320px; overflow: auto; margin-top: 4px;
}
.result-list code {
  font-family: var(--mono); font-size: 12.5px; padding: 8px 10px;
  background: #f7f9fd; border: 1px solid var(--line); border-radius: 8px;
  display: flex; justify-content: space-between; gap: 8px; cursor: pointer;
}
.result-list code:hover { border-color: #b8ccff; background: #f2f6ff; }

.skeleton { background: linear-gradient(90deg, #f1f4fa 25%, #e8edf6 37%, #f1f4fa 63%); background-size: 400% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 12px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

@media (max-width: 1240px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  #app.on { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; inset: 0 auto 0 0; width: 236px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .view { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}
