:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #e2e6ec;
  --text: #1d2229;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-dark: #1f57c8;
  --danger: #cf3b3b;
  --ok: #14804a;
  --warn: #b06a00;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(18, 28, 45, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

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

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  background: var(--accent);
  color: #fff;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}
button.ghost:hover { background: #f0f3f8; }

button.danger {
  background: #fff;
  color: var(--danger);
  border-color: #f0c9c9;
}
button.danger:hover { background: #fdf1f1; }

input, select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); }

a { color: var(--accent); }

/* ---------------- login ---------------- */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #eef3fb 0%, #f7f8fa 60%, #eef7f1 100%);
  z-index: 50;
}

.login .card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 6px; font-size: 20px; }
.login p { margin: 0 0 18px; }
.login input { width: 100%; margin-bottom: 12px; }
.login button { width: 100%; padding: 10px; }
.error { color: var(--danger); min-height: 20px; margin-top: 8px; font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------------- topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 22px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }

.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
  white-space: nowrap;
}
.tab:hover { background: transparent; color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------------- layout ---------------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 22px 60px;
}

.panel { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar input[type="search"] { flex: 1 1 260px; }
.toolbar input[type="text"] { flex: 1 1 260px; }
.toolbar select { flex: 0 1 220px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.inline-form input { flex: 1 1 160px; }
.inline-form input[type="number"] { flex: 0 1 110px; }
.inline-form select { flex: 0 1 200px; }

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 0 0 14px;
  padding-left: 2px;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
}

.grid {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
.grid th, .grid td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.grid th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  background: #fafbfd;
  position: sticky;
  top: 0;
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover { background: #f7f9fd; }
.grid tbody tr { cursor: pointer; }
.grid td.actions, .grid td.nowrap { white-space: nowrap; }
.grid td.actions button { padding: 4px 9px; font-size: 12.5px; margin: 1px 0; }
.grid .empty { text-align: center; color: var(--muted); padding: 28px; cursor: default; }

.preview { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

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

.query-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.query-box input { flex: 1 1 420px; padding: 10px 12px; }
.query-box button { padding: 10px 18px; }

.query-status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}
.query-status strong { color: var(--text); }

/* ---------------- badges & chips ---------------- */

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #eef1f6;
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: #e6f5ec; color: var(--ok); }
.badge.err { background: #fdeaea; color: var(--danger); }
.badge.off { background: #f0f0f2; color: #888; }
.badge.warn { background: #fdf3e3; color: var(--warn); }

.code-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  border: 1px dashed #b9cdf5;
  background: #f2f7ff;
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  letter-spacing: .5px;
}
.code-chip:hover { background: #e6efff; }

.err-text {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  max-width: 320px;
  word-break: break-word;
}

.token-result {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: #f2f7ff;
  border: 1px dashed #b9cdf5;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
  font-size: 13px;
}
.token-result code {
  flex: 1 1 320px;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

/* ---------------- drawer ---------------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(18, 28, 45, .14);
  padding: 18px 22px 28px;
  overflow-y: auto;
  z-index: 40;
  animation: slide .18s ease;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}
.drawer-head h2 { margin: 0; font-size: 17px; line-height: 1.35; word-break: break-word; }

.meta {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 4px 10px;
  font-size: 13px;
  color: var(--text);
  background: #f8f9fc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
.meta .k { color: var(--muted); }
.meta .v { word-break: break-all; }

.code-box {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 30px;
}
.code-box .big-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 24px;
  letter-spacing: 3px;
  color: var(--accent-dark);
  font-weight: 700;
}

.body-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.body-tabs .tab { padding: 6px 12px; }

.mail-body {
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  max-height: 60vh;
  overflow: auto;
}

.mail-html {
  width: 100%;
  height: 60vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1d2229;
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 60;
  opacity: .96;
}

/* ---------------- public page ---------------- */

.pub-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.pub-head .brand { flex: 0 0 auto; }
.pub-head .spacer { flex: 1; }

.notice {
  max-width: 720px;
  margin: 40px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.notice h2 { margin: 0 0 8px; font-size: 17px; }
.notice p { color: var(--muted); margin: 0; }

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand { font-size: 14px; }
  main { padding: 12px 12px 48px; }
  .drawer { padding: 14px 14px 24px; }
  .meta { grid-template-columns: 56px 1fr; }
}