/* ───── 设计令牌 ───── */
:root {
  --bg: #f6f7fb;
  --surface: #fff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --warn: #f59e0b;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ───── 登录 ───── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  background: #fff; padding: 32px 36px; border-radius: 14px;
  width: 360px; box-shadow: 0 20px 40px rgba(0,0,0,.15);
}
.login-title { margin: 0 0 4px; font-size: 22px; }
.login-sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

/* ───── 表单 ───── */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, input, select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; font-size: 14px; outline: none;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, input:focus, select:focus {
  border-color: var(--primary);
}

/* ───── 按钮 ───── */
.btn {
  padding: 8px 14px; border-radius: 8px;
  background: #fff; border: 1px solid var(--border); color: var(--text);
  font-size: 14px; transition: all .15s;
}
.btn:hover { border-color: #9ca3af; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.block { display: block; width: 100%; padding: 10px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.link, .link {
  background: none; border: none; color: var(--primary);
  padding: 4px 8px; font-size: 13px;
}

.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.muted { color: var(--muted); }

/* ───── 主壳 ───── */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #fff; border-right: 1px solid var(--border);
  padding: 24px 16px; display: flex; flex-direction: column;
}
.brand {
  font-size: 18px; font-weight: 600; margin-bottom: 24px;
  line-height: 1.3;
}
.brand span { font-size: 12px; color: var(--muted); font-weight: 400; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 8px; font-size: 14px; color: var(--text);
  transition: background .12s;
}
.sidebar nav a:hover { background: #f3f4f6; }
.sidebar nav a.active { background: #eff6ff; color: var(--primary); font-weight: 500; }
.who {
  margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; align-items: center;
}

.main { flex: 1; padding: 24px 32px; overflow-x: auto; }
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.page-head h2 { margin: 0; font-size: 22px; }

/* ───── 卡片 ───── */
.card {
  background: var(--surface); border-radius: var(--radius);
  border: 1px solid var(--border); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 500; }

/* ───── KPI 网格 ───── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi label { font-size: 12px; color: var(--muted); }
.kpi strong { display: block; font-size: 28px; margin-top: 4px; }
.kpi.sm strong { font-size: 22px; }

/* ───── 表格 ───── */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.table th { font-weight: 500; color: var(--muted); font-size: 13px; background: #fafbfc; }
.table tbody tr:hover { background: #f9fafb; }
.table.sm th, .table.sm td { padding: 8px 10px; }
.code-cell {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

/* ───── 状态标签 ───── */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 12px; font-weight: 500;
}
.tag.active   { background: #dcfce7; color: #166534; }
.tag.revoked  { background: #fee2e2; color: #991b1b; }
.tag.expired  { background: #f3f4f6; color: #6b7280; }
.tag.type-trial1d { background: #f3e8ff; color: #6b21a8; }
.tag.type-trial7d { background: #dbeafe; color: #1e40af; }
.tag.type-perm1   { background: #e0f2fe; color: #075985; }
.tag.type-perm2   { background: #d1fae5; color: #047857; }
.tag.type-perm3   { background: #ecfdf5; color: #065f46; }
.tag.type-perm5   { background: #fef3c7; color: #92400e; }

/* ───── 筛选 / 分页 ───── */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 140px; flex: 0 0 auto; }
.filters input[id="f-q"] { flex: 1; min-width: 200px; }

.pager {
  margin-top: 12px; display: flex; align-items: center; gap: 12px;
  justify-content: flex-end; font-size: 13px; color: var(--muted);
}

/* ───── 行 / 工具 ───── */
.row { display: flex; align-items: center; }
.row.gap8 { gap: 8px; }
.row.right { justify-content: flex-end; }

/* ───── KV 网格（详情页） ───── */
.kv-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.kv-grid > div { background: #fafbfc; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border); }
.kv-grid label { font-size: 12px; color: var(--muted); display: block; }
.kv-grid strong { font-size: 14px; word-break: break-all; }

/* ───── 弹窗 ───── */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: grid; place-items: center; z-index: 100;
}
.modal {
  background: #fff; padding: 24px; border-radius: 12px;
  width: 420px; max-width: 90vw; max-height: 80vh; overflow: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 16px; }
.gen-result {
  background: #1f2937; color: #f9fafb; padding: 12px; border-radius: 8px;
  font-size: 12px; max-height: 240px; overflow: auto; margin-top: 12px;
  font-family: ui-monospace, monospace;
}

/* ───── Toast ───── */
.toast {
  position: fixed; top: 20px; right: 20px;
  background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 8px;
  font-size: 13px; z-index: 200;
  animation: slideIn .2s ease;
}
.toast.err { background: var(--danger); }
.toast.ok  { background: var(--success); }

@keyframes slideIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* ───── 响应式 ───── */
@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; padding: 12px; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .brand { margin: 0; }
  .sidebar nav { flex-direction: row; flex: 1; margin: 0 12px; }
  .who { padding-top: 0; border: none; margin: 0; }
  .main { padding: 16px; }
  .filters input, .filters select { min-width: 120px; }
}
