:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #16181d;
  --ink-2: #5b6270;
  --ink-3: #8b93a1;
  --line: #e3e6ec;
  --line-2: #eef0f4;
  --accent: #2b5cff;
  --accent-weak: #eaefff;
  --ok: #12855a;
  --ok-weak: #e3f5ec;
  --warn: #a35b00;
  --warn-weak: #fdf0dc;
  --bad: #c02b2b;
  --bad-weak: #fdeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- 登录 */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #10131a 0%, #1b2130 55%, #25304a 100%);
  z-index: 50;
}
.gate.hidden { display: none; }

.gate-card {
  width: 380px;
  background: var(--panel);
  border-radius: 14px;
  padding: 30px 28px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .38);
}
.gate-card h1 {
  margin: 0 0 4px;
  font-size: 19px;
  letter-spacing: .2px;
}
.gate-card p.sub {
  margin: 0 0 22px;
  color: var(--ink-3);
  font-size: 12.5px;
}
.gate-card label {
  display: block;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.gate-err {
  min-height: 18px;
  color: var(--bad);
  font-size: 12.5px;
  margin-top: 10px;
}

/* ---------------------------------------------------------------- 框架 */

.shell {
  display: grid;
  grid-template-columns: 208px 1fr;
  height: 100%;
}
.shell.hidden { display: none; }

.side {
  background: #12161f;
  color: #c7cddb;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 8px 18px;
}
.logo {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #2b5cff, #6b8bff);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff;
}
.brand b { color: #fff; font-size: 14px; letter-spacing: .3px; }
.brand small { display: block; color: #6d7688; font-size: 10.5px; letter-spacing: .4px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 9px 10px;
  background: none; border: 0; border-radius: 8px;
  color: #aeb6c6; text-align: left; cursor: pointer;
}
.nav button:hover { background: rgba(255, 255, 255, .05); color: #e7ebf3; }
.nav button.on { background: rgba(43, 92, 255, .18); color: #fff; }
.nav .ico { width: 16px; text-align: center; opacity: .9; }

.side-foot {
  margin-top: auto;
  padding: 12px 8px 0;
  border-top: 1px solid rgba(255, 255, 255, .07);
  font-size: 11px; color: #6d7688;
  word-break: break-all;
}

.main { overflow: auto; padding: 22px 26px 40px; }

.head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.head h2 { margin: 0; font-size: 18px; font-weight: 650; }
.head p { margin: 2px 0 0; color: var(--ink-3); font-size: 12.5px; }

/* ---------------------------------------------------------------- 组件 */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #fafbfd; border-color: #d3d8e2; }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1f4ee0; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.sm { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line-2);
  font-weight: 600; font-size: 13.5px;
}
.card-b { padding: 16px; }

.grid-stats {
  display: grid;
  /* 固定 4 列而不是 auto-fit：8 张卡片刚好两行，不会出现 7+1 的孤儿卡 */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1180px) {
  .grid-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .grid-stats { grid-template-columns: minmax(0, 1fr); }
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .k { color: var(--ink-3); font-size: 12px; }
.stat .v { font-size: 24px; font-weight: 650; letter-spacing: -.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--ink-3); margin-left: 4px; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { color: var(--ink-3); font-size: 11.5px; margin-top: 5px; }

input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 92, 255, .12);
}
textarea { resize: vertical; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
select { cursor: pointer; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

/* ---------------------------------------------------------------- 表格 */

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
th {
  font-size: 11.5px; font-weight: 600; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .5px;
  background: #fbfcfd;
  position: sticky; top: 0;
}
tbody tr:hover { background: #fafbfe; }
tbody tr:last-child td { border-bottom: 0; }
td.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
td.num { font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 4px; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 18px;
}
.tag.unused  { background: var(--line-2); color: var(--ink-2); }
.tag.active  { background: var(--ok-weak); color: var(--ok); }
.tag.expired { background: var(--warn-weak); color: var(--warn); }
.tag.revoked { background: var(--bad-weak); color: var(--bad); }
.tag.suspect { background: var(--bad-weak); color: var(--bad); margin-left: 4px; }

.empty {
  padding: 46px 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
}

.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--line-2);
  color: var(--ink-2); font-size: 12.5px;
}

/* ---------------------------------------------------------------- 杂项 */

.toast-wrap {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 80;
}
.toast {
  padding: 10px 14px;
  border-radius: 9px;
  background: #1b2130;
  color: #eef1f7;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  animation: pop .16s ease-out;
}
.toast.bad { background: #8f2020; }
.toast.ok { background: #12603f; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.copybox {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px 12px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.8;
  max-height: 320px;
  overflow: auto;
  white-space: pre;
}

.muted { color: var(--ink-3); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- 弹窗 */

.modal {
  position: fixed; inset: 0;
  background: rgba(15, 20, 30, .45);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 70;
}
.modal-card {
  width: min(780px, 100%);
  max-height: 82vh;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-h {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-2);
  font-weight: 600; font-size: 13.5px;
}
.modal-x {
  background: none; border: 0; padding: 0 4px;
  font-size: 22px; line-height: 1;
  color: var(--ink-3); cursor: pointer;
}
.modal-x:hover { color: var(--ink); }
.modal-b { padding: 16px; overflow: auto; }

.link {
  background: none; border: 0; padding: 0;
  color: var(--accent); cursor: pointer;
  font: inherit;
}
.link:hover { text-decoration: underline; }

.dev-meta {
  display: flex; flex-wrap: wrap; gap: 6px 20px;
  color: var(--ink-2); font-size: 12.5px;
  margin-bottom: 14px;
}
.dev-meta b { color: var(--ink); font-weight: 600; }
.dev-meta .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.history-h {
  margin: 18px 0 8px;
  font-size: 12px; color: var(--ink-3);
}
tr.released td { color: var(--ink-3); }

@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; align-items: center; padding: 10px; overflow-x: auto; }
  .brand, .side-foot { display: none; }
  .nav { flex-direction: row; }
  .main { padding: 16px; }
}
