* { box-sizing: border-box; }

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(17, 24, 39, 0.08), 0 1px 2px rgba(17, 24, 39, 0.04);
}

body {
  margin: 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; }
.muted { color: var(--muted); }

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

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(37, 99, 235, 0.12), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, rgba(22, 163, 74, 0.08), transparent 55%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(17, 24, 39, 0.1);
  padding: 40px 32px 32px;
  text-align: center;
}

.logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  font-size: 28px;
  line-height: 56px;
  user-select: none;
}

.login-card h1 { margin: 0; font-size: 22px; }
.login-card .sub { margin: 4px 0 28px; color: var(--muted); }

.login-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.login-card input:focus { border-color: var(--accent); }

/* ---------- 通用 ---------- */

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  background: var(--panel);
  color: var(--text);
}

.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(17, 24, 39, 0.05); }
.btn.block { width: 100%; margin-top: 20px; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; text-align: left; }
.login-card .form-error { text-align: center; }

/* ---------- 应用框架 ---------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
}

.logo-sm {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #1e40af);
  color: #fff;
  font-size: 19px;
  line-height: 36px;
  text-align: center;
}

.brand-title { color: #f8fafc; font-weight: 600; font-size: 15px; }
.brand-sub { color: #64748b; font-size: 12px; margin-top: 1px; }

.nav {
  flex: 1;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(148, 163, 184, 0.12); color: #e2e8f0; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item svg { flex-shrink: 0; opacity: 0.9; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar-meta { font-size: 12px; color: #64748b; margin-bottom: 10px; }
.sidebar-footer .btn.ghost { color: #cbd5e1; border-color: rgba(148, 163, 184, 0.3); }
.sidebar-footer .btn.ghost:hover { background: rgba(148, 163, 184, 0.12); }
.sidebar-footer .btn.block { margin-top: 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { font-size: 17px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }

.content {
  padding: 24px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* ---------- 统计卡 ---------- */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.stat-card .label { font-size: 13px; color: var(--muted); }
.stat-card .value { font-size: 26px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-card .value small { font-size: 14px; font-weight: 400; color: var(--muted); }

/* ---------- 面板 ---------- */

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.panel.narrow { max-width: 560px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2 { margin: 0; font-size: 16px; }

.hint { font-size: 12px; color: var(--muted); }
.footnote { margin: 12px 0 0; }

/* ---------- 键值列表 ---------- */

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 24px;
}

.kv > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px dashed var(--line);
}

.kv dt { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.kv dd { margin: 0; font-size: 13px; text-align: right; word-break: break-all; }
.kv dd.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.kv .kv-empty { border: none; color: var(--muted); }

/* ---------- 资源条 ---------- */

.resources { display: flex; flex-direction: column; gap: 22px; }

.resource-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13.5px;
  margin-bottom: 8px;
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s ease;
}

.bar-fill.ok { background: linear-gradient(90deg, #2563eb, #3b82f6); }
.bar-fill.warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.bar-fill.danger { background: linear-gradient(90deg, #dc2626, #ef4444); }

.resource-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

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

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 12.5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(17, 24, 39, 0.02); }

td.num { font-variant-numeric: tabular-nums; }
.actions-col { text-align: right; }
td.actions { text-align: right; }

td .mono, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.empty { text-align: center; color: var(--muted); padding: 28px 10px !important; }

.token-cell { display: flex; align-items: center; gap: 8px; }

/* ---------- 状态徽标 ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status.ok { color: var(--success); background: rgba(22, 163, 74, 0.1); }
.status.off { color: var(--muted); background: rgba(107, 114, 128, 0.12); }
.status.err { color: var(--danger); background: rgba(220, 38, 38, 0.08); }
.status.warn { color: var(--warning); background: rgba(217, 119, 6, 0.1); }

.status-detail { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: normal; max-width: 260px; }

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  padding: 24px;
}

.modal h3 { margin: 0 0 18px; font-size: 17px; }

.modal label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.modal input[type="text"],
.modal input[type="number"],
.modal input[type="password"],
.modal select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--panel);
  outline: none;
}

.modal input:focus, .modal select:focus { border-color: var(--accent); }
.modal input:disabled { background: #f9fafb; color: var(--muted); }

.modal label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.modal label.check input { width: auto; margin: 0; }

.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; margin-top: 6px; }
.input-row .btn { margin-top: 6px; flex-shrink: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- 设置表单 ---------- */

.stack-form { max-width: 400px; }

.stack-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.stack-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  outline: none;
}

.stack-form input:focus { border-color: var(--accent); }

.form-actions { margin-top: 4px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  font-size: 13.5px;
  border-radius: 10px;
  padding: 10px 18px;
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.3);
  z-index: 100;
  max-width: 80vw;
}

/* ---------- 响应式 ---------- */

@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 0 12px; }
  .sidebar-brand { padding: 10px 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; padding: 0 0 0 8px; gap: 2px; overflow-x: auto; }
  .nav-item span { display: none; }
  .nav-item { padding: 9px 12px; }
  .sidebar-footer { padding: 0 0 0 8px; border-top: 0; display: flex; align-items: center; gap: 8px; }
  .sidebar-meta { display: none; }
  .sidebar-footer .btn.block { width: auto; margin: 0; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .topbar-right .muted { display: none; }
}
