:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-blue: #eef5ff;
  --ink: #172033;
  --muted: #667085;
  --faint: #98a2b3;
  --line: #d9e1ec;
  --line-soft: #ecf0f6;
  --blue: #1769e0;
  --blue-dark: #0f55b8;
  --green: #0f8a5f;
  --amber: #b76a00;
  --red: #c83d3d;
  --nav: #101828;
  --nav-2: #182230;
  --shadow: 0 18px 45px rgba(16, 24, 40, .08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f9fbff 0, var(--bg) 260px),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

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

.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 30px;
}

.login-card h1 { margin: 0 0 8px; font-size: 24px; letter-spacing: 0; }
.login-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.7; }
.login-submit { width: 100%; }

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--nav);
  color: #d7e1ee;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  margin: 2px 10px 24px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--blue);
  font-size: 13px;
}

.nav { display: grid; gap: 6px; }

.nav button {
  width: 100%;
  height: 42px;
  border: 0;
  color: #aebdd0;
  background: transparent;
  border-radius: 8px;
  padding: 0 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav button::before {
  content: attr(data-icon);
  width: 22px;
  color: #7f8ea3;
}

.nav button.active,
.nav button:hover {
  background: var(--nav-2);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  color: #8d9bae;
  font-size: 12px;
  line-height: 1.7;
  padding: 14px 10px 2px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.content {
  padding: 26px 28px 36px;
  max-width: 1680px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.topbar h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
.topbar .sub { color: var(--muted); margin-top: 6px; font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  min-height: 112px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat span { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat strong { font-size: 30px; letter-spacing: 0; }
.stat small { color: var(--faint); font-size: 12px; }
.stat.total { background: var(--surface-blue); border-color: #cfe2ff; }
.stat .small-strong,
.small-strong { font-size: 18px; line-height: 1.3; }
.user-stats .stat strong { overflow-wrap: anywhere; }

.security-warning {
  min-height: 48px;
  margin: -6px 0 18px;
  padding: 10px 12px;
  border: 1px solid #f0c36d;
  border-radius: 8px;
  background: #fff8e6;
  color: #7a4b00;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.security-warning span { color: #8a6114; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toolbar-left,
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.search { width: 420px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
  overflow-x: auto;
}

.panel-head {
  min-height: 58px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-soft);
}

.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 18px; }
.compact-panel { max-width: 960px; }

.card-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.card-group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}

.card-group-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.card-group-head h2 { margin: 0; font-size: 16px; }
.card-group-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.card-group-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-area {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  white-space: pre;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  border-bottom: 1px solid var(--line-soft);
  padding: 14px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th {
  color: #536174;
  background: #fbfcfe;
  font-size: 12px;
  font-weight: 800;
}

tbody tr:hover { background: #fbfdff; }
tr:last-child td { border-bottom: 0; }

.main-cell strong { display: block; font-size: 14px; margin-bottom: 4px; }
.main-cell .line { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 42px; }

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.active { color: var(--green); background: #e8f7ef; }
.status.warning { color: var(--amber); background: #fff3dc; }
.status.expired,
.status.disabled,
.status.failed { color: var(--red); background: #ffeaea; }
.status.success { color: var(--green); background: #e8f7ef; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  height: 38px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  font-weight: 700;
  box-shadow: 0 1px 1px rgba(16,24,40,.03);
}

.btn:hover { border-color: #b8c4d5; background: #fbfcfe; }
.btn.primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: #efb9b9; }
.btn.danger:hover { background: #fff5f5; }
.btn.small { height: 30px; padding: 0 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { width: 36px; padding: 0; font-size: 18px; }
.btn.large-btn { height: 88px; font-size: 18px; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: #3d4856;
  font-weight: 800;
  margin-bottom: 7px;
}

input, select, textarea {
  width: 100%;
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: white;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23,105,224,.12);
}

textarea { height: 78px; resize: vertical; padding: 10px 11px; }
input[type="checkbox"] { width: auto; height: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.check-row { display: flex; align-items: center; gap: 8px; height: 40px; color: var(--ink); }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .34);
  display: flex;
  justify-content: flex-end;
  z-index: 10;
}

.drawer {
  width: 680px;
  max-width: calc(100vw - 48px);
  background: var(--surface);
  height: 100vh;
  box-shadow: -18px 0 48px rgba(16,24,40,.22);
  display: flex;
  flex-direction: column;
}

.drawer header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fbfcfe;
}

.drawer header h2 { margin: 0; font-size: 18px; }
.drawer-body { padding: 18px 22px 24px; overflow: auto; }
.drawer footer {
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: #fbfcfe;
}

.form-section {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 14px 14px 2px;
  margin-bottom: 14px;
  background: #ffffff;
}

.section-title {
  font-size: 13px;
  font-weight: 900;
  color: #263244;
  margin: 0 0 12px;
}

.form-note {
  background: #f1f6ff;
  border: 1px solid #cfe0f8;
  border-radius: 8px;
  padding: 11px 12px;
  color: #45566f;
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 14px;
}

.redeem-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.redeem-form .field { margin-bottom: 0; }

.renew-panel { margin-top: 14px; }

.renew-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.renew-summary div {
  border: 1px solid var(--line-soft);
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 12px;
}

.renew-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.renew-summary strong {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #101828;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: 460px;
}

.log-detail {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
}

@media (max-width: 1280px) {
  .content { padding: 22px; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .search { width: 340px; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }
  .brand { margin-bottom: 12px; }
  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .nav button {
    justify-content: center;
    padding: 0 8px;
  }
  .nav button::before { display: none; }
  .sidebar-footer { display: none; }
  .content { padding: 18px; }
  .topbar { flex-direction: column; }
  .actions { justify-content: flex-start; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-left,
  .toolbar-right { width: 100%; }
  .search { width: 100%; }
  .drawer { width: 100%; max-width: 100vw; }
  .grid-2,
  .grid-3 { grid-template-columns: 1fr; }
  .redeem-form { grid-template-columns: 1fr; }
  .renew-summary { grid-template-columns: 1fr; }
}
