:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #3f5f4a;
  --primary-hover: #314c3b;
  --danger: #c62828;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; font-weight: 400; }
.error { color: var(--danger); min-height: 20px; margin: 8px 0 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 10px; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(17, 24, 39, 0.08);
}

.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-card > p { margin: 0; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #eef0f3;
  padding: 4px;
  border-radius: 10px;
  margin: 22px 0 16px;
}

.tab {
  border: 0;
  background: transparent;
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}

.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(63, 95, 74, 0.12);
}

button {
  border: 0;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: not-allowed; }

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-hover); }
.secondary { background: #eef0f3; color: var(--text); }
.secondary:hover { background: #e2e5ea; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.ghost:hover { color: var(--text); }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; display: flex; align-items: center; gap: 10px; }

.content { max-width: 1180px; margin: 0 auto; padding: 24px; }

.notice {
  background: #fff7e6;
  border: 1px solid #f5d9a8;
  color: #8a5a00;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 240px; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}

table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 500; background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.actions-col { width: 130px; }

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef0f3;
  color: #374151;
}
.badge.admin { background: #e7efe9; color: #2f4d39; }
.badge.disabled { background: #fdecec; color: #b42318; }

.row-actions { display: flex; gap: 6px; }
.row-actions button { padding: 6px 10px; font-size: 12px; }
.danger { background: #fdecec; color: var(--danger); }

.empty { padding: 28px; text-align: center; color: var(--muted); }

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

dialog {
  border: 0;
  border-radius: 14px;
  padding: 24px;
  width: min(460px, calc(100% - 32px));
  box-shadow: 0 24px 80px rgba(0,0,0,.2);
}
dialog::backdrop { background: rgba(17, 24, 39, .35); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #1f2937;
  color: #fff;
  padding: 10px 16px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}

@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .toolbar input { min-width: 100%; }
}

.nav { display: flex; gap: 6px; background: #eef0f3; padding: 4px; border-radius: 10px; }
.nav-btn {
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
}
.nav-btn.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat strong { font-size: 24px; font-weight: 600; }
.stat span { color: var(--muted); font-size: 12px; }

.toolbar select {
  width: auto;
  min-width: 120px;
  padding: 10px 12px;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.badge.unused { background: #eef0f3; color: #374151; }
.badge.active { background: #e7efe9; color: #2f4d39; }
.badge.used_up { background: #f1eefb; color: #5b45a0; }
.badge.expired { background: #fff4e5; color: #9a5b00; }

@media (max-width: 640px) {
  .nav { order: 3; width: 100%; justify-content: center; margin-top: 8px; }
  .topbar { height: auto; flex-wrap: wrap; padding: 12px 16px; gap: 8px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.row-actions { flex-wrap: nowrap; }
.row-actions button { white-space: nowrap; }
.actions-col { width: 200px; }
.badge { white-space: nowrap; }
table { min-width: 1180px; }
