:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e5e9f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #e8f0fe;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --sidebar: #111827;
  --sidebar-text: #cbd5e1;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 20px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
.hidden { display: none !important; }
a { cursor: pointer; }

/* ---------- 登录 ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
}
.login-card {
  width: 340px; padding: 28px; border-radius: 14px;
  background: #fff; box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.login-logo { font-size: 18px; font-weight: 700; text-align: center; }
.login-tip { color: var(--muted); font-size: 12px; text-align: center; margin: 8px 0 18px; }
.login-card input {
  width: 100%; padding: 10px 12px; margin-bottom: 12px;
  border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.login-error { color: var(--red); font-size: 12px; min-height: 18px; text-align: center; margin-top: 8px; }

/* ---------- 布局 ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 208px; flex: 0 0 208px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-title { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .5px; }
.brand-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 8px; color: var(--sidebar-text); text-decoration: none; font-size: 13.5px;
}
.nav a i { font-style: normal; width: 16px; text-align: center; opacity: .8; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar-foot {
  padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px; color: #94a3b8; display: flex; flex-direction: column; gap: 6px;
}
.sidebar-foot a { color: #93c5fd; }

.main { flex: 1; padding: 18px 24px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: .15s;
}
.btn:hover { border-color: #c7d2fe; color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #1d4ed8; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-size: 13px; color: var(--text); outline: none;
}
.input:focus, select:focus { border-color: var(--primary); }
.input.grow { flex: 1; min-width: 160px; }
.input.tiny { width: 76px; padding: 4px 6px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.panel-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13.5px; }
.panel-body { padding: 14px 16px; }
.panel-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

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

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: #f1f5f9; color: var(--muted); line-height: 1.7;
}
.badge.ok { background: #dcfce7; color: var(--green); }
.badge.off { background: #f1f5f9; color: var(--muted); }
.badge.warn { background: #fef3c7; color: var(--amber); }
.badge.err { background: #fee2e2; color: var(--red); }

/* ---------- 概览 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .k { color: var(--muted); font-size: 12.5px; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: .5px; }
.stat .s { color: var(--muted); font-size: 12px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: #fafbfd; white-space: nowrap; }
tr:hover td { background: #fafcff; }
td.nowrap { white-space: nowrap; }
td .clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
td .clip.open { -webkit-line-clamp: unset; }
td .cell-toggle { color: var(--primary); font-size: 12px; cursor: pointer; margin-left: 4px; }

.empty { text-align: center; color: var(--muted); padding: 28px 0; font-size: 13px; }

/* ---------- 分页 ---------- */
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; font-size: 13px; }
.pager .page-info { color: var(--muted); margin-right: 4px; }

/* ---------- 客户端 / 设置卡片 ---------- */
.client-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; }
.client-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.client-card .cc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.client-card .cc-name { font-weight: 600; }
.client-card .cc-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; word-break: break-all; }
.client-card .cc-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- 通用表单（服务器设置页也用） ---------- */
.cc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cc-form label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 2px; }
.cc-form .input { width: 100%; }

/* ---------- 弹窗（客户端详情） ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; padding: 24px;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: #fff; border-radius: 12px; width: min(780px, 100%);
  max-height: 86vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.modal-body { padding: 14px 16px; overflow: auto; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 2px 18px; margin-bottom: 14px; }
.kv > div { padding: 5px 0; border-bottom: 1px dashed #eef2f7; font-size: 13px; }
.kv span { color: var(--muted); font-size: 12px; margin-right: 8px; }

/* ---------- 聊天记录 ---------- */
.split { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.split-list .panel-body { max-height: 70vh; overflow: auto; padding: 8px; }
.split-view iframe { width: 100%; height: 72vh; border: 0; border-radius: 0 0 var(--radius) var(--radius); background: #fff; }
.chat-item { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 12.5px; }
.chat-item:hover { background: #f1f5ff; }
.chat-item.active { background: var(--primary-soft); }
.chat-item .ci-name { font-weight: 600; word-break: break-all; }
.chat-item .ci-meta { color: var(--muted); font-size: 11.5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); }

@media (max-width: 900px) {
  .sidebar { width: 64px; flex: 0 0 64px; }
  .brand-sub, .nav a span, .nav a i + * { display: none; }
  .nav a { justify-content: center; font-size: 0; }
  .nav a i { font-size: 16px; }
  .sidebar-foot { display: none; }
  .panel-row, .split { grid-template-columns: 1fr; }
  .main { padding: 12px; }
}
