:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ---------- 表单元素 ---------- */
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
input:disabled { background: #f8fafc; color: var(--muted); }
input[type="checkbox"] { width: auto; }

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--primary);
  color: #fff;
  font-family: inherit;
}
button:hover { filter: brightness(.94); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--text); border-color: var(--border); }
button.danger { background: var(--danger); }
button.small { padding: 4px 10px; font-size: 12px; }
button.link { background: none; border: none; color: var(--primary); padding: 2px 6px; font-size: 13px; }
button.link.danger { color: var(--danger); }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #0ea5e9 100%);
}
.login-card {
  width: 380px;
  max-width: 92vw;
  background: var(--card);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.login-card .brand { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 22px; }
.app-chip {
  background: #eff6ff;
  color: var(--primary-dark);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}
.alert {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-card label, .form-row label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 6px;
}
.login-card button[type="submit"] { width: 100%; margin-top: 22px; padding: 11px; font-size: 15px; }
.hint { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- 通用错误页 ---------- */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.error-card {
  width: 440px;
  max-width: 92vw;
  background: var(--card);
  border-radius: 14px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .08);
}
.error-card .icon { font-size: 44px; margin-bottom: 14px; }
.error-card h1 { font-size: 20px; margin-bottom: 10px; }
.error-card p { color: var(--muted); line-height: 1.7; margin-bottom: 20px; }

/* ---------- 用户门户 ---------- */
.portal-topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.portal-topbar .brand { font-size: 17px; font-weight: 700; }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-box .uname { color: var(--muted); }
.section-title { padding: 26px 32px 4px; font-size: 17px; }
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
  padding: 18px 32px 40px;
}
.app-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.app-card .app-name { font-size: 16px; font-weight: 600; }
.app-card .app-desc { color: var(--muted); font-size: 13px; min-height: 20px; }
.app-card .app-meta { color: var(--muted); font-size: 12px; }
.app-card .enter { margin-top: 8px; text-align: center; display: block; padding: 9px; border-radius: 8px; background: var(--primary); color: #fff; }
.empty {
  padding: 60px 32px;
  text-align: center;
  color: var(--muted);
}

/* ---------- 管理台布局 ---------- */
.admin-page { min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #0f172a;
  color: #cbd5e1;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.sidebar .logo { font-size: 15px; font-weight: 700; color: #fff; padding: 20px 18px; border-bottom: 1px solid #1e293b; }
.sidebar nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.sidebar nav a:hover { background: #1e293b; text-decoration: none; }
.sidebar nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 14px; border-top: 1px solid #1e293b; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer a { color: #94a3b8; font-size: 13px; }
.sidebar-footer form button { width: 100%; background: #1e293b; }

.admin-main { margin-left: 220px; padding: 0 26px 40px; }
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.topbar h1 { font-size: 18px; }
.topbar .who { color: var(--muted); font-size: 13px; }

/* 统计卡片 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.panel-title { font-size: 15px; margin: 18px 0 10px; }

/* 表格 */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; vertical-align: middle; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8fafc; }
td.ops { white-space: nowrap; }
td.empty-row { text-align: center; color: var(--muted); padding: 30px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px; word-break: break-all; }

/* 徽标 */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 12px;
  background: #f1f5f9;
  color: var(--muted);
  white-space: nowrap;
}
.badge.on { background: #dcfce7; color: var(--success); }
.badge.off { background: #fee2e2; color: var(--danger); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.info { background: #dbeafe; color: var(--primary-dark); }

/* 分页 */
.pager { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: var(--muted); font-size: 13px; }

/* 弹窗 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px;
  z-index: 50;
  overflow: auto;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: 12px;
  width: 480px;
  max-width: 94vw;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal h3 { font-size: 16px; margin-bottom: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.form-row.check { display: flex; align-items: center; gap: 8px; }
.form-row.check label { margin: 0; color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.tip {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.copy-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.copy-row input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.copy-row button { flex-shrink: 0; }

/* Toast */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all .2s;
  z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- 第三方登录 ---------- */
.oauth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  margin: 20px 0 12px;
}
.oauth-divider::before, .oauth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.oauth-btns { display: flex; gap: 10px; }
.oauth-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  background: #fff;
}
.oauth-btn:hover { text-decoration: none; filter: brightness(.97); border-color: #cbd5e1; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.p-wechat .dot, .dot.p-wechat { background: #07c160; }
.p-alipay .dot, .dot.p-alipay { background: #1677ff; }
.p-google .dot, .dot.p-google { background: #ea4335; }

/* 账号绑定面板（门户） */
.bind-panel {
  margin: 0 32px 40px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 20px;
}
.bind-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.bind-row:last-child { border-bottom: none; }
.bind-row b { font-size: 14px; }
.bind-row .spacer { flex: 1; }
