:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 12px;
  background: #eef2f7;
  padding: 1px 5px;
  border-radius: 4px;
  color: #334155;
}

/* ---------------- 登录 ---------------- */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #eef4ff 0%, #f7f9fc 45%, #f5f7fa 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .1);
  padding: 26px 26px 22px;
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.login-brand h1 { margin: 0; font-size: 18px; font-weight: 650; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-tip { margin-top: 14px; line-height: 1.7; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
  flex: none;
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { min-width: 0; }
.brand h1 { margin: 0; font-size: 15px; font-weight: 650; }
.brand p { margin: 0; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.project-picker { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.project-picker select { min-width: 180px; }

.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-chip > span:first-child { font-weight: 600; }

/* ---------------- 标签页 ---------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 63px;
  z-index: 15;
  overflow-x: auto;
}

.tab {
  font: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 11px 14px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------------- 布局 ---------------- */
main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }

.hint { color: var(--muted); font-size: 12px; margin: 0; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0 0; }

/* ---------------- 概览 ---------------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 22px; font-weight: 650; letter-spacing: -.3px; }
.stat-sub { font-size: 11px; color: var(--muted); }

.endpoint-list { display: flex; flex-direction: column; gap: 10px; }
.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  flex-wrap: wrap;
}
.endpoint-label { font-size: 12px; color: var(--muted); min-width: 96px; }
.endpoint code { background: #fff; border: 1px solid var(--line); padding: 4px 8px; word-break: break-all; }

/* ---------------- 表单 ---------------- */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.span2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field > span em { font-style: normal; color: #9ca3af; }
.field.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field.checkbox > span { font-size: 13px; color: var(--text); }

input[type="text"], input[type="password"], input[type="file"], textarea, select {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
select { cursor: pointer; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; }

/* ---------------- 按钮 ---------------- */
.btn {
  font: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: #fff; border-color: #d1d5db; color: var(--text); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.btn.tiny { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; padding: 10px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------- 进度条 ---------------- */
.progress { height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .12s linear; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tbody tr:hover { background: #fafbff; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
td.empty { text-align: center; color: var(--muted); padding: 22px; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 18px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.ok { color: var(--ok); background: #ecfdf5; border-color: #a7f3d0; }
.badge.warn { color: var(--warn); background: #fffbeb; border-color: #fde68a; }
.badge.off { color: var(--muted); background: #f3f4f6; border-color: #e5e7eb; }
.badge.bad { color: var(--danger); background: #fef2f2; border-color: #fecaca; }
.badge.info { color: var(--primary); background: #eff6ff; border-color: #bfdbfe; }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- 项目卡片 ---------------- */
.project-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }

.project-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-card.current { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.project-title { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.project-title strong { font-size: 14px; }
.project-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 10px; }
.project-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.key-box {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 6px;
  padding: 6px 8px;
  word-break: break-all;
  color: #334155;
}

/* ---------------- 对话框 ---------------- */
.dialog-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.dialog {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
.dialog h3 { margin: 0 0 14px; font-size: 15px; }
.dialog .field { margin-bottom: 12px; }
.dialog-actions { justify-content: flex-end; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, .25);
  z-index: 100;
  max-width: 80vw;
}
.toast.bad { background: #b91c1c; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
  main { padding: 14px; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .tabs { padding: 0 14px; top: 0; position: static; }
  .project-picker select { min-width: 130px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .topbar-right { width: 100%; justify-content: space-between; }
}
