:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #7a869a;
  --line: #e5e9f2;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --orange: #d97706;
  --red: #dc2626;
  --sidebar: #111827;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 13px; word-break: break-all; }
.nowrap { white-space: nowrap; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: 0 0 216px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary);
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.brand strong { display: block; color: #fff; font-size: 15px; letter-spacing: .5px; }
.brand small { color: #8b98ad; font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.sidebar nav a {
  color: #cbd5e1; padding: 10px 12px; border-radius: 8px; font-size: 14px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-bottom { margin-top: auto; }
.sidebar-user { color: #8b98ad; font-size: 12px; padding: 12px 6px 0; }
.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(16,24,40,.03);
}
.card.narrow { max-width: 560px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat strong { display: block; font-size: 26px; margin-top: 6px; font-weight: 600; }
.stat.green strong { color: var(--green); }
.stat.orange strong { color: var(--orange); }
.stat.red strong { color: var(--red); }
.stat.blue strong { color: var(--primary); }

.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: #fafbfe; }
td.empty, .empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.table-wrap { width: 100%; overflow-x: auto; }

.codes-table .actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.codes-table .actions form { margin: 0; }
.codes-table .actions .inline { display: inline-flex; gap: 4px; align-items: center; }

input, select {
  height: 36px; border: 1px solid #cfd6e4; border-radius: 8px; padding: 0 10px;
  font-size: 14px; color: var(--ink); background: #fff; outline: none; width: 100%;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
input.mini { width: 64px; height: 30px; padding: 0 6px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row label { width: 110px; }
.form-row label.grow { flex: 1; min-width: 180px; }
.stack { display: flex; flex-direction: column; gap: 14px; max-width: 380px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input { width: 240px; }
.filters select { width: 120px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid #cfd6e4;
  background: #fff; color: var(--ink); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #b7c1d4; background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--red); border-color: #f1c4c4; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { background: transparent; border-color: #374151; color: #cbd5e1; }
.btn.ghost:hover { background: rgba(255,255,255,.06); }
.btn.small { height: 30px; padding: 0 10px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }

.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.badge.green { background: #e8f7ee; color: #15803d; }
.badge.gray { background: #eef1f6; color: #64748b; }
.badge.orange { background: #fef3e2; color: #b45309; }
.badge.red { background: #fdecec; color: #b91c1c; }
.tag {
  display: inline-block; padding: 2px 7px; border-radius: 6px; background: #eef2ff;
  color: #4338ca; font-size: 12px; font-family: Consolas, monospace;
}

.flashes { margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 10px 12px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.flash.success { background: #ecfdf3; border-color: #bbf7d0; color: #166534; }
.flash.error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flashes.standalone { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 10; min-width: 320px; }

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

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; box-shadow: 0 10px 30px rgba(16,24,40,.08); display: flex; flex-direction: column; gap: 16px;
}
.login-brand { padding: 0 0 6px; }
.login-brand strong { color: var(--ink); }
.login-card h2 { font-size: 18px; }
.login-card label { font-size: 13px; }
.login-card .btn { margin-top: 4px; }
.login-card p { margin: 0; text-align: center; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex: none; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-bottom { margin-top: 12px; }
  .main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-row label, .form-row label.grow { width: 100%; }
  .filters input { width: 100%; }
}