:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e8eaef;
  --line-soft: #f0f2f5;

  --text: #1a1d26;
  --text-2: #5b6270;
  --text-3: #8b92a1;

  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef0fe;

  --ok: #0f9960;
  --ok-soft: #e6f6ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e3;
  --bad: #d64545;
  --bad-soft: #fdecec;

  --side: #151823;
  --side-2: #9aa1b1;
  --side-hover: #1f2432;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 32, .04), 0 4px 16px rgba(16, 20, 32, .05);
  --shadow-lg: 0 12px 48px rgba(16, 20, 32, .16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.grow { flex: 1; }
.right { text-align: right; }
.muted { color: var(--text-2); }

/* The sprite only exists to host <symbol> definitions. */
.sprite { display: none; }

svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

/* Operators must never see administration surfaces. The server refuses them
   regardless; hiding here keeps the panel from advertising what it will
   reject. */
body.role-operator .admin-only { display: none !important; }

/* ─── 表单元素 ─────────────────────────────────────── */

input, select, textarea, button { font-family: inherit; font-size: 14px; }

input[type=text], input[type=password], input[type=number],
input[type=search], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
input::placeholder { color: var(--text-3); }
input:disabled, select:disabled {
  background: var(--line-soft); color: var(--text-3); cursor: not-allowed;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b92a1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
textarea {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px; line-height: 1.8; resize: vertical;
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; margin-bottom: 6px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
}

.check {
  display: flex; align-items: center; gap: 9px;
  margin: 4px 0 16px; font-size: 13px; color: var(--text-2);
  cursor: pointer; user-select: none;
}
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* ─── 按钮 ────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:hover { background: var(--line-soft); border-color: #dcdfe6; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }

.btn.primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 1px 2px rgba(79, 70, 229, .3);
}
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn.danger:hover { background: #fbdcdc; }

.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--line-soft); color: var(--text); }

.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.xs { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn.lg { padding: 11px 22px; font-size: 14.5px; }
.btn.block { width: 100%; }
.btn.icon { padding: 8px; }
.btn.icon svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ─── 登录页 ──────────────────────────────────────── */

.auth {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, #e9e7fd 0%, transparent 55%),
    radial-gradient(800px 460px at 105% 110%, #dfeafc 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 390px;
  background: var(--surface);
  padding: 34px 32px 28px;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}
.auth-brand, .side-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand { margin-bottom: 26px; }
.auth-brand strong, .side-brand strong { display: block; font-size: 15.5px; letter-spacing: .2px; }
.auth-brand span, .side-brand span { font-size: 12.5px; color: var(--text-3); }

.logo {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(140deg, var(--brand), #7c6df2);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .32);
}
.logo svg { width: 21px; height: 21px; stroke-width: 2; }

/* ─── 布局骨架 ────────────────────────────────────── */

/* The sidebar is fixed, so it contributes no width to the flow. Laying the
   shell out as a block lets .main's auto width subtract its own margin instead
   of stretching to the full viewport and overflowing by the sidebar's width. */
.shell { min-height: 100vh; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 232px; padding: 20px 14px;
  display: flex; flex-direction: column;
  background: var(--side);
  color: #fff;
}
.side-brand { padding: 4px 8px 22px; }
.side-brand span { color: var(--side-2); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--side-2);
  font-size: 14px; text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 500; }
.nav-item.active svg { stroke-width: 2.1; }

.side-user {
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 10px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.avatar {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(140deg, var(--brand), #7c6df2);
  font-size: 14px; font-weight: 600; text-transform: uppercase;
}
.side-user-info { min-width: 0; }
.side-user-info strong {
  display: block; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-user-info span { font-size: 12px; color: var(--side-2); }

.side-actions { display: flex; flex-direction: column; gap: 2px; padding-top: 6px; }
.side-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--side-2);
  font-size: 13px; text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.side-btn:hover { background: var(--side-hover); color: #fff; }
.side-btn svg { width: 16px; height: 16px; }

.main { margin-left: 232px; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: 20px 32px 16px;
  background: rgba(246, 247, 249, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.2px; }
.topbar-sub { margin: 3px 0 0; font-size: 13px; color: var(--text-3); }

.content { padding: 22px 32px 56px; }

/* ─── 统计卡 ──────────────────────────────────────── */

.stats {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.stat {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.stat-icon {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand);
}
.stat.ok .stat-icon { background: var(--ok-soft); color: var(--ok); }
.stat.warn .stat-icon { background: var(--warn-soft); color: var(--warn); }
.stat.bad .stat-icon { background: var(--bad-soft); color: var(--bad); }
.stat-text { min-width: 0; }
.stat-text span { display: block; font-size: 12px; color: var(--text-3); margin-bottom: 1px; }
.stat-text strong { font-size: 20px; font-weight: 650; letter-spacing: -.4px; }

/* ─── 卡片容器 ────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head select { width: auto; min-width: 140px; }
.card-title { font-size: 15px; font-weight: 600; }

.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.search { position: relative; flex: 0 1 280px; }
.search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-3); pointer-events: none;
}
.search input { padding-left: 34px; }

.note-bar {
  margin: 0; padding: 11px 18px;
  background: #fbfcfd; border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--text-2); line-height: 1.65;
}

.cost { margin: 2px 0 16px; font-size: 13px; color: var(--text-2); min-height: 20px; }
.cost.bad { color: var(--bad); font-weight: 500; }

/* The freshly issued batch is the one thing on this page that cannot be
   recovered after it scrolls away, so it gets the accent treatment. */
.batch { margin-bottom: 14px; border-color: #cfcbf8; }
.batch .card-head { background: var(--brand-soft); border-bottom-color: #dcd8fa; }
.batch .card-title { color: var(--brand); }
.codes {
  border: none; border-radius: 0;
  padding: 14px 18px; letter-spacing: .3px;
}
.codes:focus { box-shadow: none; }

/* ─── 表格 ────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 16px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: var(--text-3);
  text-align: left; letter-spacing: .3px; white-space: nowrap;
}
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px; white-space: nowrap; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fbfcfd; }

td.code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px; letter-spacing: .2px;
}
/* A button rather than a click handler on the cell, so the code stays
   reachable by keyboard and reads as interactive to a screen reader. */
.code-btn {
  padding: 0; border: none; background: none;
  font-family: inherit; font-size: inherit; letter-spacing: inherit;
  color: inherit; cursor: pointer;
  border-bottom: 1px dashed transparent;
}
.code-btn:hover { color: var(--brand); border-bottom-color: var(--brand); }

tr.fresh td { background: #f7f6ff; }
tr.fresh td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
tbody tr.fresh:hover td { background: #f2f0fe; }
td.note {
  white-space: normal; max-width: 220px;
  color: var(--text-2); font-size: 13px;
}
td.empty { padding: 40px 16px; text-align: center; color: var(--text-3); }
td.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
td.delta.up { color: var(--ok); }
td.delta.down { color: var(--bad); }

.actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ─── 徽标 ────────────────────────────────────────── */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.pill::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}
.pill.unused { background: var(--line-soft); color: var(--text-2); }
.pill.active { background: var(--ok-soft); color: var(--ok); }
.pill.revoked { background: var(--bad-soft); color: var(--bad); }
.pill.expired { background: var(--warn-soft); color: var(--warn); }
.pill.role { background: var(--brand-soft); color: var(--brand); }
.pill.role::before { display: none; }

/* ─── 弹窗 ────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(20, 24, 35, .45);
  backdrop-filter: blur(3px);
  animation: fade .16s ease;
}
.modal-card {
  width: 100%; max-width: 620px; max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: rise .2s cubic-bezier(.2, .8, .3, 1);
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 17px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head strong { flex: 1; font-size: 15.5px; }
.modal-body { padding: 20px; overflow: auto; }
.modal-body .table-wrap { margin: 0 -20px -20px; }
.modal-body th:first-child, .modal-body td:first-child { padding-left: 20px; }
.modal-body th:last-child, .modal-body td:last-child { padding-right: 20px; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }

/* ─── 提示条 ──────────────────────────────────────── */

.msg { min-height: 18px; margin: 12px 0 0; font-size: 13px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

.toasts {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 400px;
  padding: 13px 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: slide-in .22s cubic-bezier(.2, .8, .3, 1);
}
.toast.out { animation: slide-out .18s ease forwards; }
.toast.ok { border-left-color: var(--ok); }
.toast.ok svg { color: var(--ok); }
.toast.err { border-left-color: var(--bad); }
.toast.err svg { color: var(--bad); }
.toast svg { margin-top: 1px; color: var(--brand); }

@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } }
@keyframes slide-out { to { opacity: 0; transform: translateX(20px); } }

/* ─── 窄屏 ────────────────────────────────────────── */

@media (max-width: 860px) {
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 12px;
    padding: 10px 14px; overflow-x: auto;
  }
  .side-brand, .side-user-info, .side-btn span { display: none; }
  .nav { flex-direction: row; }
  .nav-item span { display: none; }
  .nav-item { padding: 9px 11px; }
  .side-user { margin: 0 0 0 auto; border: none; padding: 0; }
  .side-actions { flex-direction: row; padding: 0; }
  .main { margin-left: 0; }
  .topbar { padding: 16px 18px 12px; }
  .content { padding: 16px 18px 40px; }
}
