:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #2563eb 100%); }
.login-card { background: #fff; padding: 40px 36px; border-radius: 16px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { font-size: 44px; text-align: center; }
.login-card h1 { text-align: center; font-size: 20px; margin: 8px 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 24px; }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
.login-card input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.login-card form { margin-bottom: 18px; }
.login-card .btn-block { margin-top: 18px; }
.login-tip { margin-top: 16px; color: var(--red); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 18px 16px; font-size: 17px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand small { font-size: 11px; font-weight: 400; color: #64748b; margin-left: 4px; }
#nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
#nav .nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: var(--sidebar-text); font-size: 14px; margin-bottom: 2px; transition: background .15s; }
#nav .nav-item:hover { background: rgba(255,255,255,.06); }
#nav .nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
#nav .nav-item .ico { width: 20px; text-align: center; }
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.side-user { font-size: 13px; color: var(--sidebar-text); }
.side-user b { display: block; color: #fff; }
.side-user span { font-size: 11px; color: #64748b; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.pill { background: #fef3c7; color: #92400e; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.content { flex: 1; overflow-y: auto; padding: 20px; }
.view { max-width: 1400px; margin: 0 auto; }

/* ---------- 组件 ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { font-size: 15px; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

.stat { padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat .num { font-size: 30px; font-weight: 800; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 13px; margin-top: 6px; }
.stat.green .num { color: var(--green); }
.stat.red .num { color: var(--red); }
.stat.yellow .num { color: var(--yellow); }
.stat.blue .num { color: var(--primary); }

.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid transparent; font-size: 13px; font-weight: 600; transition: all .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--primary); font-size: 13px; padding: 2px 6px; }
.btn-link.danger { color: var(--red); }
.btn-link.muted { color: var(--muted); }

/* 懒人三键 */
.lazy-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.lazy-btn { border-radius: 14px; padding: 22px; color: #fff; text-align: left; cursor: pointer; border: none; box-shadow: var(--shadow); transition: transform .12s; }
.lazy-btn:hover { transform: translateY(-2px); }
.lazy-btn .big { font-size: 28px; display: block; margin-bottom: 6px; }
.lazy-btn .t { font-size: 18px; font-weight: 800; display: block; }
.lazy-btn .d { font-size: 12px; opacity: .9; margin-top: 4px; display: block; }
.lazy-btn.scan { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.lazy-btn.repair { background: linear-gradient(135deg, #d97706, #b45309); }
.lazy-btn.maintain { background: linear-gradient(135deg, #16a34a, #15803d); }

/* 系统状态卡 */
.sys-card { padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); }
.sys-card .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sys-card .name { font-weight: 700; font-size: 15px; }
.sys-card .code { color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.dot.up { background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.2); }
.dot.degraded { background: var(--yellow); box-shadow: 0 0 0 3px rgba(217,119,6,.2); }
.dot.down, .dot.unknown { background: var(--red); box-shadow: 0 0 0 3px rgba(220,38,38,.2); }
.dot.disabled { background: #94a3b8; }
.metrics { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 12px; color: var(--muted); }
.metrics b { color: var(--text); }
.meter { height: 5px; background: #e2e8f0; border-radius: 3px; margin: 4px 0 8px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--green); }
.meter i.warn { background: var(--yellow); }
.meter i.crit { background: var(--red); }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: top; }
th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
tr:hover td { background: #f8fafc; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.gray { background: #f1f5f9; color: #475569; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.critical { background: #7f1d1d; color: #fff; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #eef6ff; }

/* 过滤条 */
.filterbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filterbar input, .filterbar select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.filterbar input:focus, .filterbar select:focus { outline: none; border-color: var(--primary); }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-lg { width: 720px; }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form-grid input, .form-grid select, .form-grid textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .chk { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.confirm-msg { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 12px; border-radius: 8px; margin-bottom: 12px; line-height: 1.6; }
.danger-check { display: flex; align-items: center; gap: 8px; color: var(--red); font-weight: 600; font-size: 13px; }

/* AI 聊天 */
.ai-layout { display: grid; grid-template-columns: 260px 1fr; gap: 16px; height: calc(100vh - 140px); }
.ai-convs { overflow-y: auto; }
.ai-conv-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.ai-conv-item:hover { background: var(--bg); }
.ai-conv-item.active { background: #dbeafe; border-color: #bfdbfe; }
.chat-box { display: flex; flex-direction: column; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; }
.msg { margin-bottom: 12px; max-width: 80%; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.user { margin-left: auto; }
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 2px; }
.msg.assistant .bubble { background: #f1f5f9; border-bottom-left-radius: 2px; }
.chat-input { display: flex; gap: 10px; padding: 12px; border-top: 1px solid var(--border); }
.chat-input textarea { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px; resize: none; height: 52px; }
.quick-row { display: flex; gap: 8px; padding: 0 12px 8px; flex-wrap: wrap; }

/* 知识库 */
.kb-card { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.kb-card h4 { margin-bottom: 6px; }
.kb-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.kb-card p { font-size: 13px; color: #334155; line-height: 1.6; }
.kb-card .fix { background: #f0fdf4; border-left: 3px solid var(--green); padding: 8px 10px; border-radius: 4px; margin-top: 8px; }
.kb-card .cmd { background: #0f172a; color: #a5f3fc; padding: 8px 10px; border-radius: 6px; font-family: Consolas, monospace; font-size: 12px; margin-top: 8px; white-space: pre-wrap; }

/* Toast */
.toast { position: fixed; top: 20px; right: 20px; background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 8px; z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 360px; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { background: none; border: none; padding: 8px 14px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

@media (max-width: 900px) {
  .lazy-row { grid-template-columns: 1fr; }
  .ai-layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { width: 64px; }
  .sidebar .brand span, .sidebar .nav-item span.txt, .sidebar .side-user, .sidebar .brand small { display: none; }
}
