:root {
  --ink: #17231d;
  --muted: #607067;
  --line: #dce3de;
  --surface: #ffffff;
  --surface-soft: #f6f8f6;
  --canvas: #eef2ef;
  --green: #27684c;
  --green-strong: #18533b;
  --green-soft: #dfeee6;
  --blue: #2b659f;
  --blue-soft: #e3edf7;
  --amber: #9a6518;
  --amber-soft: #f7ecd7;
  --red: #a63e3e;
  --red-soft: #f6e3e3;
  --shadow: 0 14px 36px rgba(26, 48, 36, 0.09);
  --font: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; display: block; }
[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(125deg, rgba(25, 83, 59, 0.96), rgba(19, 46, 34, 0.98)),
    repeating-linear-gradient(90deg, transparent 0 72px, rgba(255,255,255,0.03) 72px 73px);
}
.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border-radius: 8px;
  padding: 38px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--green);
}
.brand-mark svg { width: 30px; height: 30px; }
.brand-mark.small { width: 38px; height: 38px; }
.brand-mark.small svg { width: 22px; height: 22px; }
.login-copy { margin: 25px 0 28px; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 9px; font-size: 25px; line-height: 1.25; }
h2 { margin-bottom: 5px; font-size: 18px; }
.login-copy p:last-child { margin-bottom: 0; color: var(--muted); line-height: 1.7; }
.form-stack { display: grid; gap: 17px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.field input, .field select,
.search-field,
select {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
.field input { padding: 0 13px; }
.field input:focus, .search-field:focus-within, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(39, 104, 76, 0.12);
}
.form-error { min-height: 20px; margin: -4px 0 0; color: var(--red); font-size: 13px; }
.button {
  height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}
.button svg { width: 17px; height: 17px; }
.button-wide { width: 100%; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-strong); }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button-secondary:hover { border-color: #b9c7be; background: var(--surface-soft); }
.button-danger { background: var(--red); color: #fff; }
.button:disabled { opacity: 0.55; cursor: wait; }
.login-hint { margin: 19px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

.app-view { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 14px 16px;
  color: #eef5f1;
  background: #173c2c;
  display: flex;
  flex-direction: column;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 25px; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand span { display: block; margin-top: 3px; color: #a9c2b5; font-size: 11px; }
.nav { display: grid; gap: 4px; }
.nav-item {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 11px;
  color: #bfd1c7;
  background: transparent;
  text-align: left;
}
.nav-item svg { width: 18px; height: 18px; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: #fff; color: var(--green-strong); font-weight: 700; }
.sidebar-footer { margin-top: auto; display: grid; gap: 3px; }
.sidebar-footer #admin-name {
  margin: 14px 10px 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.12);
  color: #a9c2b5;
  font-size: 12px;
}

.main { min-width: 0; padding: 0 30px 34px; }
.topbar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.topbar h1 { margin: 0; font-size: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.server-state {
  height: 30px;
  padding: 0 11px;
  border: 1px solid #cfe1d7;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--green-strong);
  background: #eef7f2;
  font-size: 12px;
}
.server-state i { width: 7px; height: 7px; border-radius: 50%; background: #3a966b; box-shadow: 0 0 0 3px #d4eadf; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
}
.icon-button:hover { background: var(--surface-soft); }
.page { display: none; }
.page.active { display: block; }
.stat-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.stat {
  min-height: 116px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(34, 57, 44, 0.04);
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { margin: 16px 0 4px; font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-note { color: var(--muted); font-size: 12px; }
.stat.accent-green { border-top: 3px solid #3c8b62; }
.stat.accent-blue { border-top: 3px solid #4e80b2; }
.stat.accent-amber { border-top: 3px solid #ba8433; }
.section-heading {
  margin: 28px 0 12px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 13px 14px; border-bottom: 1px solid #edf0ee; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: #fafbfa; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfb; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.truncate { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.active { color: var(--green-strong); background: var(--green-soft); }
.badge.unused { color: var(--blue); background: var(--blue-soft); }
.badge.disabled { color: var(--red); background: var(--red-soft); }
.badge.expired { color: var(--amber); background: var(--amber-soft); }
.toolbar {
  min-height: 56px;
  margin-bottom: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.filter-group { display: flex; gap: 10px; flex: 1; }
.search-field {
  width: min(420px, 100%);
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.search-field.wide { width: min(540px, 100%); }
.search-field svg { width: 17px; height: 17px; color: var(--muted); }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
select { min-width: 130px; padding: 0 32px 0 11px; }
.pager { min-height: 48px; display: flex; justify-content: flex-end; align-items: center; gap: 7px; color: var(--muted); }
.pager button {
  width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}
.pager button:disabled { opacity: 0.4; cursor: default; }
.action-menu {
  position: fixed;
  z-index: 30;
  width: 170px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.action-menu button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 0 10px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.action-menu button:hover { background: var(--surface-soft); }
.action-menu button.danger { color: var(--red); }
.empty { padding: 40px 18px; color: var(--muted); text-align: center; }

.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(14, 28, 20, 0.48); backdrop-filter: blur(2px); }
.modal {
  position: fixed;
  z-index: 41;
  top: 50%;
  left: 50%;
  width: min(560px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 38px));
  transform: translate(-50%, -50%);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(0,0,0,0.25);
  overflow: hidden;
}
.modal.wide { width: min(760px, calc(100vw - 28px)); }
.modal-header { padding: 20px 22px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px; }
.modal-header h2 { margin: 0; }
.modal-body { max-height: calc(100vh - 170px); padding: 20px 22px 24px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field textarea {
  min-height: 90px;
  resize: vertical;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
}
.field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(39,104,76,.12); }
.notice {
  padding: 12px 14px;
  border: 1px solid #ead8b6;
  border-radius: 7px;
  color: #73501c;
  background: #fbf5e9;
  line-height: 1.7;
}
.code-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.code-row {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-soft);
}
.code-row code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.code-row button { border: 0; background: transparent; color: var(--green); }
.toast-stack { position: fixed; z-index: 60; right: 22px; bottom: 22px; display: grid; gap: 8px; }
.toast {
  min-width: 240px;
  max-width: 420px;
  padding: 12px 14px;
  border: 1px solid #cbded3;
  border-radius: 7px;
  color: #173c2c;
  background: #f0f8f4;
  box-shadow: var(--shadow);
}
.toast.error { border-color: #e5c1c1; color: #7d2929; background: #fbefef; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .app-view { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 13px;
  }
  .sidebar-brand { padding-bottom: 12px; }
  .nav { grid-template-columns: repeat(4, 1fr); }
  .nav-item { justify-content: center; padding: 0 6px; font-size: 12px; }
  .nav-item svg { display: none; }
  .sidebar-footer { margin-top: 8px; grid-template-columns: 1fr 1fr; }
  .sidebar-footer #admin-name { display: none; }
  .main { padding: 0 16px 28px; }
  .topbar { min-height: 80px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar, .filter-group { align-items: stretch; flex-direction: column; }
  .toolbar .button, .search-field, select { width: 100%; }
}
@media (max-width: 520px) {
  .login-panel { padding: 28px 22px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 24px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .topbar-actions .server-state { display: none; }
}
