/* 卡密授权管理后台 —— 深色主题，无外部依赖 */
:root {
  --bg: #0e1014;
  --bg2: #14171e;
  --panel: #171b23;
  --panel2: #1d222c;
  --line: #262c38;
  --line2: #333b4a;
  --text: #e7eaf0;
  --dim: #8d96a8;
  --primary: #3b82f6;
  --primary2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --purple: #8b5cf6;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* hidden 属性必须压过 .login-wrap 的 display:grid，否则登录页永远盖在上面 */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: radial-gradient(1200px 600px at 15% -10%, #16233a 0%, transparent 55%), var(--bg);
  color: var(--text);
  font: 14px/1.55 "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.tiny { font-size: 11.5px; }
.dim { color: var(--dim); }
.mono { font-family: "Consolas", "SF Mono", monospace; }
.grow { flex: 1; }
.hide { display: none !important; }

/* ---------------------------------------------------------- 登录页 */
.login-wrap {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 28px 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.brand .logo {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, #4f8df7, #1d4ed8); color: #fff;
  font-size: 22px; font-weight: 700; flex: 0 0 auto;
}
.brand.sm { margin-bottom: 18px; }
.brand.sm .logo { width: 34px; height: 34px; font-size: 17px; border-radius: 9px; }
.brand p { margin-top: 2px; }

.login-card label { display: block; margin-bottom: 14px; font-size: 12.5px; color: var(--dim); }
.login-card input { margin-top: 6px; }
input, select, textarea {
  width: 100%; background: var(--bg2); color: var(--text);
  border: 1px solid var(--line2); border-radius: 9px; padding: 9px 11px; font: inherit;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}
input::placeholder { color: #5b6478; }
select { cursor: pointer; }
textarea { resize: vertical; min-height: 64px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line2);
  border-radius: 9px; padding: 8px 14px; font: inherit; cursor: pointer;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #46506a; background: #222835; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(145deg, #4f8df7, var(--primary2)); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: #ffb4b4; border-color: #5b2a2a; background: #2a1a1a; }
.btn.danger:hover { background: #3a2020; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.err { color: #ff9b9b; font-size: 12.5px; min-height: 18px; margin-top: 8px; }

/* ---------------------------------------------------------- 布局 */
#app { display: flex; min-height: 100vh; }

.side {
  width: 214px; flex: 0 0 214px; background: #101319; border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh;
}
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
#nav button {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: transparent; border: 0; color: #b6bdcb; padding: 9px 11px;
  border-radius: 9px; font: inherit; cursor: pointer; transition: .15s;
}
#nav button:hover { background: #1a1f29; color: var(--text); }
#nav button.on { background: #1e2a44; color: #cfe0ff; font-weight: 600; }
#nav button.on::before {
  content: ""; width: 3px; height: 15px; border-radius: 2px; background: var(--primary);
  margin-left: -11px; margin-right: 8px;
}
#nav .grp {
  font-size: 11px; color: #596274; padding: 14px 11px 5px; letter-spacing: .5px;
}
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; }
.who { font-size: 12.5px; margin-bottom: 9px; color: var(--dim); line-height: 1.5; }
.who b { color: var(--text); font-size: 13.5px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; flex: 0 0 60px; display: flex; align-items: center; gap: 14px;
  padding: 0 26px; border-bottom: 1px solid var(--line); background: rgba(16, 19, 25, .7);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
#view { padding: 22px 26px 60px; max-width: 1400px; width: 100%; }

.chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px;
  border: 1px solid var(--line2); color: var(--dim); background: #171b23;
}
.chip.blue { color: #a9c9ff; border-color: #2b3f63; background: #16233a; }
.chip.green { color: #a5e8bd; border-color: #24513a; background: #14261d; }
.chip.orange { color: #ffd7a3; border-color: #5a4020; background: #2a1f12; }
.chip.red { color: #ffb4b4; border-color: #5b2a2a; background: #2a1a1a; }
.chip.gray { color: #9aa3b5; }

/* ---------------------------------------------------------- 卡片 / 统计 */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
.card > h3 { margin-bottom: 4px; }
.card .sub { font-size: 12.5px; color: var(--dim); margin-bottom: 14px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; position: relative; overflow: hidden;
}
.stat .k { font-size: 12.5px; color: var(--dim); margin-bottom: 7px; }
.stat .v { font-size: 25px; font-weight: 700; letter-spacing: -.5px; line-height: 1.15; }
.stat .u { font-size: 12px; color: var(--dim); margin-left: 3px; font-weight: 400; }
.stat::after {
  content: ""; position: absolute; right: -26px; top: -26px; width: 76px; height: 76px;
  border-radius: 50%; background: rgba(59, 130, 246, .10);
}
.stat.g::after { background: rgba(34, 197, 94, .10); }
.stat.o::after { background: rgba(245, 158, 11, .12); }
.stat.p::after { background: rgba(139, 92, 246, .12); }

/* ---------------------------------------------------------- 表格 */
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 12px; background: #151922; color: var(--dim);
  font-weight: 500; font-size: 12px; white-space: nowrap; border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid #1d222c; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #161b23; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--dim); padding: 34px 0 !important; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }

.page-bar {
  display: flex; align-items: center; gap: 10px; padding: 12px 2px 0; font-size: 12.5px;
  color: var(--dim);
}

/* ---------------------------------------------------------- 表单 / 工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.toolbar .grow { flex: 1 1 auto; }

.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 0; min-width: 96px; background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 10px; padding: 11px 10px; color: var(--dim); cursor: pointer; font: inherit;
  text-align: center; transition: .15s;
}
.seg button b { display: block; color: var(--text); font-size: 13.5px; margin-bottom: 2px; }
.seg button.on { border-color: var(--primary); background: #17243c; color: #a9c9ff; }
.seg button.on b { color: #dbe9ff; }

.sumbox {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; gap: 22px; align-items: center; flex-wrap: wrap;
}
.sumbox .it { font-size: 12.5px; color: var(--dim); }
.sumbox .it b { color: var(--text); font-size: 16px; margin-left: 5px; }

/* ---------------------------------------------------------- 弹窗 */
.mask {
  position: fixed; inset: 0; background: rgba(6, 8, 12, .66); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px; z-index: 50; animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: 100%; max-width: 620px; max-height: 86vh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line2); border-radius: 14px; padding: 20px 22px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6);
}
.modal.wide { max-width: 860px; }
.modal h3 { margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.codes {
  background: #0c0f14; border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font-family: Consolas, monospace; font-size: 13px; line-height: 1.9; max-height: 300px;
  overflow: auto; white-space: pre; letter-spacing: .4px; color: #b9e5c8;
}

/* ---------------------------------------------------------- 提示 */
#toasts {
  position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column;
  gap: 8px; z-index: 99;
}
.toast {
  background: #1b2029; border: 1px solid var(--line2); border-left: 3px solid var(--primary);
  border-radius: 9px; padding: 10px 15px; font-size: 13px; min-width: 190px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .45); animation: slide .18s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
@keyframes slide { from { transform: translateX(18px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------------------------------------------------------- 响应式 */
@media (max-width: 1080px) {
  .g5, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .side {
    width: 100%; flex: none; height: auto; position: static; flex-direction: row;
    align-items: center; gap: 8px; overflow-x: auto; padding: 10px 12px;
  }
  .side .brand { display: none; }
  #nav { flex-direction: row; overflow: visible; }
  #nav .grp { display: none; }
  #nav button { white-space: nowrap; }
  .side-foot { border: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
  .who { display: none; }
  #view { padding: 14px; }
  .topbar { padding: 0 14px; height: 52px; flex-basis: 52px; }
  .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2 { grid-template-columns: 1fr; }
  .stat .v { font-size: 21px; }
  .row2, .row3 { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .g4, .g5 { grid-template-columns: 1fr; }
}
