:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --border: #e5e5ea;
  --border-strong: #d2d2d7;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #0071e3;
  --black: #1d1d1f;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9500;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.05), 0 16px 40px rgba(0, 0, 0, 0.08);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}
* { box-sizing: border-box; }
::selection { background: rgba(0, 113, 227, 0.16); }
:focus-visible { outline: 3px solid rgba(0, 113, 227, 0.32); outline-offset: 2px; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; transition: opacity 0.2s var(--ease); }
a:hover { opacity: 0.72; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--red); font-size: 13px; margin-top: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace; font-size: 12px; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 28px;
  background: var(--bg);
}
.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px;
  box-shadow: var(--shadow);
  animation: rise 0.5s var(--ease) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; margin: 16px 0 4px; }
.logo, .brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--black);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.03em;
}
.login-card label { display: block; margin-top: 18px; font-size: 12px; color: var(--muted); font-weight: 500; }
.login-card input {
  width: 100%;
  margin-top: 7px;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}
.login-card .btn { width: 100%; margin-top: 22px; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100%; }
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--border);
  padding: 26px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 600; letter-spacing: -0.02em; padding: 0 8px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; letter-spacing: 0; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  color: #515154;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), transform 0.18s var(--ease);
}
#nav a:hover { background: #f2f2f7; color: var(--text); transform: translateX(1px); }
#nav a.active { background: #f2f2f7; color: var(--text); font-weight: 600; }
.side-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 0 10px; font-size: 12px; }
.main { flex: 1; min-width: 0; width: 100%; margin: 0 auto; padding: 34px 40px 70px; max-width: 1560px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.topbar h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.03em; margin: 0; font-weight: 600; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.view { display: flex; flex-direction: column; gap: 18px; animation: fadeUp 0.35s var(--ease) both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- components ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 20px; transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), border-color 0.25s var(--ease); }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: #dcdce1; }
.card .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.card .value { font-size: 31px; font-weight: 600; letter-spacing: -0.035em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.panel { padding: 22px; }
.panel h2 { font-size: 16px; letter-spacing: -0.02em; margin: 0 0 16px; font-weight: 600; }
.panel h3 { font-size: 14px; margin: 20px 0 10px; color: #3a3a3c; font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 0.16s var(--ease), background 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), opacity 0.18s var(--ease);
}
.btn:hover { background: #f5f5f7; border-color: #c7c7cc; transform: translateY(-1px); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--black); border-color: var(--black); color: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.btn.primary:hover { background: #000; border-color: #000; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16); }
.btn.danger { background: #fff; border-color: #ffd1ce; color: var(--red); }
.btn.danger:hover { background: #fff5f4; border-color: #ffb3ae; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; transform: none; box-shadow: none; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; transition: color 0.18s var(--ease); }
.link:hover { color: var(--text); }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: #b8b8be; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12); }
label.field { display: flex; flex-direction: column; gap: 7px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid #f0f0f2; font-size: 13px; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr { transition: background 0.16s var(--ease); }
tbody tr:hover td { background: #fafafc; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 34px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 500; border: 1px solid transparent; white-space: nowrap; }
.badge.unused { color: #6e6e73; background: #f5f5f7; border-color: #e5e5ea; }
.badge.active, .badge.paid { color: #1c7c3a; background: #eaf8ee; border-color: #c9efd3; }
.badge.expired, .badge.banned, .badge.revoked { color: #c4271e; background: #fff0ef; border-color: #ffd6d2; }
.badge.exhausted, .badge.pending { color: #a05a00; background: #fff6e8; border-color: #ffe1b8; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding-top: 12px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bar i {
  display: block;
  width: 100%;
  max-width: 34px;
  background: linear-gradient(180deg, #ff9f6b, #ff6b35);
  border-radius: 7px 7px 3px 3px;
  min-height: 2px;
  transition: height 0.45s var(--ease), filter 0.2s var(--ease);
}
.bar:hover i { filter: brightness(1.06); }
.bar span { font-size: 10px; color: var(--muted); }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.28); backdrop-filter: blur(14px); display: grid; place-items: center; padding: 24px; z-index: 50; animation: fadeIn 0.2s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  width: min(900px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.2);
  animation: pop 0.28s var(--ease) both;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal-box header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(12px); z-index: 1; border-radius: 22px 22px 0 0; }
.modal-box h2 { font-size: 17px; letter-spacing: -0.02em; margin: 0; font-weight: 600; }
.modal-box #modal-body { padding: 22px; }
.icon { background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; transition: color 0.18s var(--ease), transform 0.18s var(--ease); }
.icon:hover { color: var(--text); transform: rotate(90deg); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 9px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; word-break: break-all; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 15px; background: #f5f5f7; border: 1px dashed var(--border-strong); border-radius: 12px; padding: 14px; text-align: center; word-break: break-all; }

.toast { position: fixed; right: 24px; bottom: 24px; background: var(--black); border: 1px solid var(--black); color: #fff; padding: 12px 17px; border-radius: 12px; z-index: 100; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22); animation: toastIn 0.3s var(--ease) both; }
.toast.error { background: #c4271e; border-color: #c4271e; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; padding: 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  #nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; }
  .main { padding: 20px; }
  .topbar h1 { font-size: 24px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 110px 1fr; }
}
