:root {
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #666;
  --line: #e2e6ea;
  --accent: #0b6bcb;
  --danger: #c0392b;
  --ok: #1e7e34;
  --top-h: 52px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  background: #15202b;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
}
.top-left, .top-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
}
.top strong { margin-right: 4px; }
.top a { color: #d7e7ff; text-decoration: none; white-space: nowrap; }
.top a:hover { color: #fff; text-decoration: underline; }
.wrap {
  width: 100%;
  max-width: 1280px;
  margin: 16px auto;
  padding: 0 12px 40px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  margin: 10vh auto;
}
.login-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}
.login-actions button { min-width: 88px; }
button.btn-secondary {
  background: #6b7280;
}
button.btn-secondary:hover { background: #4b5563; }
label { display: block; margin: 10px 0 4px; font-size: 14px; }
input, select, button, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-width: 100%;
}
input, select, textarea { width: 100%; }
button {
  width: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}
button.danger { background: var(--danger); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin: 12px 0 20px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--muted); font-size: 13px; }

/* 表格横向滚动，小屏不挤裂 */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}
table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  background: var(--card);
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
th { background: #eef2f6; white-space: nowrap; }
.th-sort {
  color: inherit;
  text-decoration: none;
  display: inline-block;
  padding: 2px 0;
}
.th-sort:hover { color: var(--accent); text-decoration: underline; }
.th-sort.active { color: var(--accent); font-weight: 700; }

/* CDK 表：列间距与宽度 */
.cdk-table {
  table-layout: fixed;
  min-width: 980px;
  border: none;
}
.cdk-table th,
.cdk-table td {
  padding: 10px 14px;
  vertical-align: middle;
}
.cdk-table .col-code { width: 22%; }
.cdk-table .col-dur { width: 10%; white-space: nowrap; }
.cdk-table .col-status { width: 10%; white-space: nowrap; }
.cdk-table .col-mid { width: 18%; }
.cdk-table .col-expire { width: 16%; white-space: nowrap; }
.cdk-table .col-note {
  width: 14%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cdk-table .col-ops { width: 12%; }
.cdk-table .code-text { margin-right: 4px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; white-space: nowrap; }
.muted { color: var(--muted); }
.err { color: var(--danger); }
.ok { color: var(--ok); }
tr.ok { background: #f3fff5; }
tr.off { opacity: 0.65; }

/* 状态列：保证「已吊销」三字同行 */
.col-status,
th.col-status,
td.col-status {
  min-width: 4.5em;
  width: 4.5em;
  white-space: nowrap;
  word-break: keep-all;
}

.ops form { display: inline; margin-right: 4px; }
.ops-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
  min-width: 150px;
}
.ops-row form { display: inline-block; margin: 0; }
.ops-row .ops-delete { margin-left: auto; }
.search {
  margin: 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.search input { flex: 1 1 200px; min-width: 0; }
.copy-btn {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 9999;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  max-width: min(90vw, 520px);
  text-align: center;
}
.toast-ok {
  background: #e8f5e9;
  color: #1b5e20;
  border: 1px solid #a5d6a7;
}
.toast-err {
  background: #ffebee;
  color: #b71c1c;
  border: 1px solid #ef9a9a;
}
.muted { color: #888; font-size: 13px; }
.card .muted { margin: 0 0 12px; }

h1 { font-size: clamp(1.25rem, 2.5vw, 1.6rem); margin: 0 0 8px; }
h2 { font-size: clamp(1.05rem, 2vw, 1.25rem); }

@media (max-width: 900px) {
  .wrap { margin-top: 12px; padding: 0 10px 32px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .top { padding: 10px 12px; }
  .top strong { display: block; width: 100%; margin-bottom: 4px; }
}

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .login-card { margin: 6vh auto; }
  .top-left a, .top-right a { font-size: 14px; }
  table { min-width: 860px; }
  th, td { padding: 8px; font-size: 12px; }
}

@media (min-width: 1400px) {
  .wrap { max-width: 1400px; }
}
