:root {
  --bg: #070d17;
  --bg2: #0b1424;
  --panel: #101a2c;
  --panel2: #16233a;
  --line: #22304c;
  --text: #e8eefb;
  --muted: #8ea3c4;
  --accent: #4a8cff;
  --accent2: #38bdf8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a855f7;
  --radius: 14px;
  --shadow: 0 20px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 12% -10%, #16294a 0%, transparent 60%),
              radial-gradient(900px 600px at 100% 0%, #14304a 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
::selection { background: rgba(74, 140, 255, .35); }

/* ---------------------------------------------------------------- login */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(160deg, rgba(22, 35, 58, .96), rgba(12, 20, 34, .98));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 38px 34px 30px;
  box-shadow: var(--shadow);
  animation: pop .35s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.login-logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 22px; letter-spacing: .5px;
  box-shadow: 0 10px 26px rgba(74, 140, 255, .38);
  margin-bottom: 18px;
}
.login-card h1 { font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.login-card p.sub { color: var(--muted); margin: 6px 0 24px; font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 7px; letter-spacing: .3px; }
.input, .select, textarea.input {
  width: 100%;
  background: rgba(9, 16, 28, .85);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 13px;
  font-size: 14px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
  font-family: inherit;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 140, 255, .16);
}
textarea.input { resize: vertical; min-height: 74px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 10px 16px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: transform .12s, filter .18s, background .18s;
  font-family: inherit; color: #fff; background: var(--panel2); white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #4a8cff, #3568dd); box-shadow: 0 8px 20px rgba(74, 140, 255, .28); }
.btn-green { background: linear-gradient(135deg, #22c55e, #15803d); }
.btn-red { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.btn-amber { background: linear-gradient(135deg, #f59e0b, #b45309); }
.btn-ghost { background: rgba(255, 255, 255, .04); border-color: var(--line); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; padding: 12px; font-size: 14.5px; }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12.5px; font-family: inherit; }

.err { color: #ff8f8f; font-size: 13px; min-height: 18px; margin: 4px 0 10px; }

/* ---------------------------------------------------------------- shell */
#app { display: none; min-height: 100vh; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: linear-gradient(180deg, rgba(16, 26, 44, .96), rgba(8, 14, 24, .98));
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center; font-weight: 800;
  box-shadow: 0 8px 18px rgba(74, 140, 255, .3);
}
.brand div small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.brand div b { font-size: 14.5px; letter-spacing: .3px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; color: var(--muted);
  cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: background .16s, color .16s;
  user-select: none;
}
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.nav-item:hover { background: rgba(255, 255, 255, .045); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(74, 140, 255, .22), rgba(74, 140, 255, .05));
  color: #fff; box-shadow: inset 0 0 0 1px rgba(74, 140, 255, .3);
}
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 12px; color: var(--muted); padding: 8px 12px; border-top: 1px solid var(--line); margin-top: 8px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.topbar h2 { font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.topbar .crumb { color: var(--muted); font-size: 12.5px; margin-top: 5px; }

.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- cards / panels */
.panel {
  background: linear-gradient(160deg, rgba(22, 35, 58, .72), rgba(12, 20, 33, .8));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
}
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h3 { font-size: 14.5px; font-weight: 650; }
.panel-head .hint { color: var(--muted); font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat {
  background: linear-gradient(150deg, rgba(26, 41, 68, .9), rgba(13, 22, 37, .92));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 17px;
  position: relative; overflow: hidden;
}
.stat::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 90px; height: 90px;
  border-radius: 50%; background: radial-gradient(circle, rgba(74, 140, 255, .25), transparent 70%);
}
.stat .k { color: var(--muted); font-size: 12.5px; margin-bottom: 9px; }
.stat .v { font-size: 25px; font-weight: 750; letter-spacing: .5px; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 5px; }
.stat.green .v { color: #5ee08e; }
.stat.amber .v { color: #ffc861; }
.stat.blue .v { color: #7fb0ff; }
.stat.purple .v { color: #c79bff; }
.stat.red .v { color: #ff8f8f; }

.grid2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 980px; }
thead th {
  text-align: left; padding: 11px 13px; color: var(--muted); font-weight: 600; font-size: 12.5px;
  background: rgba(10, 17, 29, .8); border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 11px 13px; border-bottom: 1px solid rgba(34, 48, 76, .55); vertical-align: middle; }
tbody tr:hover { background: rgba(74, 140, 255, .06); }
tbody tr:last-child td { border-bottom: none; }
td { white-space: nowrap; }
td.wrap { white-space: normal; }
.code-cell b, .copy-btn { white-space: nowrap; }
td:last-child .btn { padding: 6px 9px; font-size: 12px; }
td.mono, .mono { font-family: "JetBrains Mono", Consolas, "Courier New", monospace; letter-spacing: .4px; }
.code-cell { display: flex; align-items: center; gap: 7px; }
.copy-btn {
  border: 1px solid var(--line); background: rgba(255, 255, 255, .03); color: var(--muted);
  border-radius: 6px; padding: 2px 6px; font-size: 11px; cursor: pointer; font-family: inherit;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.empty { padding: 42px 10px; text-align: center; color: var(--muted); font-size: 13px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 11.8px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge.unused { background: rgba(148, 163, 184, .13); color: #b6c4d8; border-color: rgba(148, 163, 184, .22); }
.badge.active { background: rgba(34, 197, 94, .14); color: #5ee08e; border-color: rgba(34, 197, 94, .3); }
.badge.expired { background: rgba(239, 68, 68, .13); color: #ff9a9a; border-color: rgba(239, 68, 68, .28); }
.badge.disabled { background: rgba(148, 163, 184, .1); color: #8b9ab1; border-color: rgba(148, 163, 184, .2); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters .input, .filters .select { width: auto; min-width: 130px; }
.filters .search { min-width: 230px; flex: 1; max-width: 340px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pager .info { color: var(--muted); font-size: 12.5px; }
.pager .pages { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pager button {
  min-width: 33px; height: 33px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, .03); color: var(--text); cursor: pointer; font-size: 12.5px;
  font-family: inherit; padding: 0 9px;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager button.on { background: linear-gradient(135deg, #4a8cff, #3568dd); border-color: transparent; font-weight: 700; }
.pager button:disabled { opacity: .35; cursor: not-allowed; }

.bulkbar {
  display: none; align-items: center; gap: 10px; padding: 10px 13px; margin-bottom: 12px;
  border-radius: 10px; background: rgba(74, 140, 255, .1); border: 1px solid rgba(74, 140, 255, .3);
  font-size: 13px; flex-wrap: wrap;
}
.bulkbar.show { display: flex; }
input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ---------------------------------------------------------------- modal */
.mask {
  position: fixed; inset: 0; background: rgba(3, 7, 14, .72); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 22px; z-index: 90;
}
.mask.show { display: flex; }
.modal {
  width: 100%; max-width: 520px; max-height: 88vh; overflow: auto;
  background: linear-gradient(160deg, #17233a, #0c1421);
  border: 1px solid var(--line); border-radius: 18px; padding: 22px;
  box-shadow: var(--shadow); animation: pop .22s ease;
}
.modal.wide { max-width: 760px; }
.modal h3 { font-size: 16px; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
@media (max-width: 560px) { .row2 { grid-template-columns: 1fr; } }
.switch { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); cursor: pointer; }
.hint-text { color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.6; }

.codes-box {
  background: rgba(6, 12, 21, .9); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; max-height: 220px; overflow: auto; font-family: Consolas, monospace;
  font-size: 12.5px; line-height: 1.85; white-space: pre-wrap; word-break: break-all; color: #cfe0ff;
}

/* ---------------------------------------------------------------- toast */
#toasts { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 200; }
.toast {
  min-width: 200px; max-width: 360px; padding: 11px 15px; border-radius: 11px; font-size: 13px;
  background: rgba(20, 32, 52, .97); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: slide .22s ease;
}
.toast.ok { border-color: rgba(34, 197, 94, .5); color: #b7f5cd; }
.toast.err { border-color: rgba(239, 68, 68, .5); color: #ffc4c4; }
@keyframes slide { from { opacity: 0; transform: translateX(18px); } }

.bar-chart { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 10px; }
.bar-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }
.bar-chart .bar {
  width: 100%; max-width: 42px; border-radius: 7px 7px 3px 3px; min-height: 4px;
  background: linear-gradient(180deg, #4a8cff, rgba(74, 140, 255, .28));
  transition: height .4s ease;
}
.bar-chart .lbl { color: var(--muted); font-size: 11px; }
.bar-chart .num { font-size: 11.5px; color: #b9cdf0; }
.type-legend { display: flex; flex-direction: column; gap: 11px; }
.type-legend .row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.type-legend .swatch { width: 9px; height: 9px; border-radius: 3px; }
.type-legend .grow { flex: 1; color: var(--muted); }
.progress { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, .07); overflow: hidden; width: 100%; }
.progress i { display: block; height: 100%; border-radius: 4px; }
