:root {
  color: #202226;
  background: #f4f5f6;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --border: #d9dde2;
  --muted: #69717d;
  --surface: #ffffff;
  --ink: #202226;
  --green: #18794e;
  --green-soft: #e8f4ed;
  --red: #b42318;
  --red-soft: #fcebea;
  --amber: #946200;
  --amber-soft: #fff4d6;
  --blue: #1f5fbf;
  --blue-soft: #eaf1fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f4f5f6;
  color: var(--ink);
}

button, input { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  color: #f8fafc;
  background: #202226;
  border-bottom: 1px solid #101214;
}

.brand, .session, .system-state {
  display: flex;
  align-items: center;
}

.brand { gap: 10px; }
.brand strong { font-size: 15px; font-weight: 650; }

.brand-mark {
  width: 14px;
  height: 14px;
  background: #4fd1a1;
  border: 2px solid #202226;
  outline: 1px solid #4fd1a1;
}

.session { gap: 18px; font-size: 12px; color: #cbd1d8; }
.system-state { gap: 7px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #e0a800; }
.system-state.ok .status-dot { background: #4fd1a1; }
.system-state.error .status-dot { background: #ff7468; }
.admin-email { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-action {
  padding: 5px 8px;
  border: 1px solid #4a4e54;
  border-radius: 4px;
  color: #e5e9ee;
  background: transparent;
  font-size: 12px;
}
.topbar-action:hover { background: #303338; }

main { width: 100%; }

.summary-band {
  background: #eef0f2;
  border-bottom: 1px solid var(--border);
}

.summary-grid {
  width: min(1180px, calc(100% - 56px));
  min-height: 112px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
}

.metric {
  min-width: 0;
  padding: 4px 24px;
  border-left: 1px solid var(--border);
}
.metric:first-child { border-left: 0; padding-left: 0; }
.metric span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.metric strong { display: block; font-size: 25px; line-height: 1; font-weight: 650; }

.content-section {
  width: min(1180px, calc(100% - 56px));
  margin: 0 auto;
  padding: 30px 0 4px;
}

.section-heading {
  min-height: 44px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}
.section-heading.compact { min-height: auto; margin-bottom: 12px; }
.section-heading h1, .section-heading h2 { margin: 0; font-size: 18px; line-height: 1.35; font-weight: 650; }
.section-heading h2 { font-size: 15px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.button {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 5px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.button:disabled { cursor: not-allowed; opacity: .55; }
.button.primary { color: #fff; background: #256d50; border-color: #1e5d44; }
.button.primary:hover { background: #1e5d44; }
.button.secondary { color: var(--ink); background: #fff; border-color: var(--border); }
.button.secondary:hover { background: #f4f5f6; }
.button.danger { color: var(--red); background: #fff; border-color: #e5b9b5; }
.button.danger:hover { background: var(--red-soft); }
.button.small { min-height: 30px; padding: 5px 9px; font-size: 12px; }

.table-shell {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 13px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid #e7e9ec; }
th { color: var(--muted); background: #fafbfb; font-size: 11px; font-weight: 650; text-transform: uppercase; }
td { font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
th:nth-child(1) { width: 27%; }
th:nth-child(2) { width: 12%; }
th:nth-child(3) { width: 20%; }
th:nth-child(4) { width: 14%; }
th:nth-child(5) { width: 27%; }

.user-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 620; }
.user-email { display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.status-pill { display: inline-flex; min-width: 48px; justify-content: center; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 650; }
.status-pill.active { color: var(--green); background: var(--green-soft); }
.status-pill.expired { color: var(--amber); background: var(--amber-soft); }
.status-pill.scheduled { color: var(--blue); background: var(--blue-soft); }
.status-pill.revoked { color: var(--red); background: var(--red-soft); }
.expiry-main { display: block; white-space: nowrap; }
.expiry-sub { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.ip-count.warning { color: var(--red); font-weight: 650; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.actions-heading { text-align: right; }
.empty-state { padding: 44px 20px; color: var(--muted); text-align: center; font-size: 13px; }

.audit-section { padding-bottom: 48px; }
.audit-list { border-top: 1px solid var(--border); }
.audit-item { min-height: 44px; display: grid; grid-template-columns: 160px minmax(0, 1fr) 210px; align-items: center; gap: 14px; border-bottom: 1px solid var(--border); font-size: 12px; }
.audit-type { font-weight: 620; }
.audit-detail, .audit-time { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-time { text-align: right; }

dialog {
  width: min(430px, calc(100% - 32px));
  padding: 0;
  border: 1px solid #cbd0d6;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 18px 50px rgba(20, 24, 28, .22);
}
dialog::backdrop { background: rgba(20, 24, 28, .45); }
dialog form { padding: 20px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.dialog-heading h2 { margin: 0; font-size: 17px; }
.icon-button { width: 30px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; }
.icon-button:hover { color: var(--ink); background: #f0f2f3; }
label { display: block; margin-top: 14px; }
label > span { display: block; margin-bottom: 6px; color: #4f5660; font-size: 12px; font-weight: 620; }
input { width: 100%; height: 38px; padding: 8px 10px; border: 1px solid #cbd0d6; border-radius: 5px; color: var(--ink); background: #fff; outline: none; }
input:focus { border-color: #2f7d5d; box-shadow: 0 0 0 3px rgba(47, 125, 93, .13); }
.dialog-context { margin: -6px 0 8px; color: var(--muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(380px, calc(100% - 44px));
  padding: 11px 14px;
  border-radius: 6px;
  color: #fff;
  background: #202226;
  box-shadow: 0 8px 24px rgba(20, 24, 28, .24);
  font-size: 13px;
}
.toast.error { background: #8f2018; }

.login-page { background: #eef0f2; }
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-panel {
  width: min(380px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(20, 24, 28, .1);
}
.login-brand { margin-bottom: 28px; }
.login-brand strong { font-size: 16px; }
.login-panel h1 { margin: 0 0 20px; font-size: 20px; font-weight: 650; }
.login-panel label { margin-top: 0; }
.login-submit { width: 100%; margin-top: 22px; }
.login-error { margin: 12px 0 -6px; color: var(--red); font-size: 12px; }

@media (max-width: 820px) {
  .topbar { padding: 0 16px; }
  .admin-email { display: none; }
  .summary-grid, .content-section { width: calc(100% - 28px); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 0; }
  .metric { min-height: 58px; padding: 8px 14px; }
  .metric:nth-child(3) { border-left: 0; }
  .table-shell { overflow-x: auto; }
  table { min-width: 780px; }
  .audit-item { grid-template-columns: 130px minmax(0, 1fr); }
  .audit-time { display: none; }
}

@media (max-width: 520px) {
  .content-section { padding-top: 22px; }
  .section-heading { align-items: center; }
  .section-heading p { max-width: 190px; }
  .metric strong { font-size: 21px; }
  .table-shell { overflow: visible; border: 0; background: transparent; }
  table { display: block; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; }
  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
  }
  tbody tr:hover { background: var(--surface); }
  td { min-width: 0; padding: 12px; border-bottom: 0; }
  td:nth-child(1) { grid-column: 1; }
  td:nth-child(2) { grid-column: 2; text-align: right; }
  td:nth-child(3), td:nth-child(4) { border-top: 1px solid #e7e9ec; }
  td:nth-child(4) { text-align: right; }
  td:nth-child(5) { grid-column: 1 / -1; padding-top: 10px; border-top: 1px solid #e7e9ec; }
  td:nth-child(3)::before, td:nth-child(4)::before {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 650;
    text-transform: uppercase;
  }
  td:nth-child(3)::before { content: "有效期"; }
  td:nth-child(4)::before { content: "近 5 分钟 IP"; }
  .row-actions { justify-content: flex-start; }
  .login-panel { padding: 22px; }
}
