:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d5d9e0;
  --text: #1f2329;
  --text-2: #4e5969;
  --muted: #86909c;
  --primary: #4d6bfe;
  --primary-soft: #eef1ff;
  --primary-dark: #3a52d6;
  --danger: #d93026;
  --danger-soft: #fdeceb;
  --warn: #d97706;
  --warn-soft: #fef5e7;
  --ok: #12a150;
  --ok-soft: #e8f7ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 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.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
code, .mono { font-family: var(--mono); }

/* ---------------- 登录 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #e8ecff 0%, var(--bg) 55%);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(16, 24, 40, .08);
  padding: 32px 28px 28px;
}
.login-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7c93ff);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; margin-bottom: 18px;
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; letter-spacing: -.2px; }
.login-card p.sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: #14161c;
  color: #c9cdd4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  padding: 20px 18px 18px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #7c93ff);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.brand .name { color: #fff; font-weight: 600; font-size: 14px; letter-spacing: .2px; }
.brand .sub { font-size: 11px; color: #7a808c; margin-top: 1px; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  cursor: pointer; color: #c9cdd4; font-size: 13.5px;
  border: none; background: none; text-align: left; width: 100%;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav-item .ico { width: 16px; height: 16px; flex: 0 0 16px; opacity: .9; }

.sidebar-foot {
  margin-top: auto; padding: 14px 16px; font-size: 11.5px; color: #7a808c;
  border-top: 1px solid rgba(255,255,255,.07); display: flex; flex-direction: column; gap: 6px;
}
.sidebar-foot .row { display: flex; justify-content: space-between; gap: 8px; }
.sidebar-foot .val { color: #c9cdd4; }

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

.topbar {
  height: 56px; flex: 0 0 56px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: -.1px; }
.topbar .right { display: flex; align-items: center; gap: 10px; }

.content { padding: 20px 22px 40px; max-width: 1320px; width: 100%; }

/* ---------------- 通用组件 ---------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 12px;
}
.card-head h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.card-head .hint { font-size: 12px; color: var(--muted); }
.card-body { padding: 16px; }

.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat { padding: 16px; }
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 25px; font-weight: 600; letter-spacing: -.6px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 13px; border-radius: 7px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text-2);
  cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: all .12s;
}
.btn:hover { border-color: #b8bfcc; color: var(--text); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c2be; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f2f3f5; }
.btn.sm { height: 27px; padding: 0 9px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .select, textarea.input {
  width: 100%; height: 34px; padding: 0 11px;
  border: 1px solid var(--border-strong); border-radius: 7px;
  background: #fff; color: var(--text); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(77,107,254,.12);
}
.input::placeholder { color: #b3b9c4; }
label.field { display: block; margin-bottom: 13px; }
label.field > span.lbl { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
label.field > span.tip { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 21px; padding: 0 8px; border-radius: 20px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: #f2f3f5; color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--primary-soft); color: var(--primary-dark); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.tbl th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--panel-2);
  white-space: nowrap;
}
table.tbl td { padding: 11px 12px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover td { background: #fafbfe; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 44px 16px; text-align: center; color: var(--muted); font-size: 13px; }

.alert-bar {
  margin: 16px 22px -4px;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid #f0c2be;
  background: var(--danger-soft);
  color: #9f2019;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}
.alert-bar .ico-warn {
  flex: 0 0 16px; width: 16px; height: 16px; margin-top: 1px;
}
.alert-bar code {
  background: rgba(0,0,0,.05); padding: 1px 5px; border-radius: 4px; font-size: 12px;
}

.bar-track { height: 5px; background: #eef0f4; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .3s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--danger); }

.keytext {
  font-family: var(--mono); font-size: 12px; color: var(--text-2);
  background: #f6f7f9; border: 1px solid var(--border);
  padding: 3px 7px; border-radius: 5px; letter-spacing: .2px;
}

/* ---------------- 弹窗 ---------------- */
.mask {
  position: fixed; inset: 0; background: rgba(15, 18, 25, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 24px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 480px;
  box-shadow: 0 20px 48px rgba(16,24,40,.18);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: 0; } to { transform: none; opacity: 1; } }
.modal.wide { max-width: 720px; }
.modal-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px 20px; overflow: auto; }
.modal-foot {
  padding: 13px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 9px; background: var(--panel-2);
  border-radius: 0 0 12px 12px;
}
.close-x { cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; padding: 2px 4px; border: none; background: none; }
.close-x:hover { color: var(--text); }

/* ---------------- 对话气泡 ---------------- */
.msg { margin-bottom: 14px; }
.msg .role {
  font-size: 11.5px; color: var(--muted); margin-bottom: 5px;
  display: flex; align-items: center; gap: 7px;
}
.msg .bubble {
  padding: 10px 13px; border-radius: 9px; white-space: pre-wrap; word-break: break-word;
  font-size: 13.2px; line-height: 1.65;
}
.msg.user .bubble { background: var(--primary-soft); color: #23293a; }
.msg.assistant .bubble { background: #f6f7f9; border: 1px solid var(--border); }
.msg.system .bubble, .msg.tool .bubble {
  background: #fbfbfc; border: 1px dashed var(--border-strong); color: var(--text-2); font-size: 12.5px;
}
.msg img { max-width: 100%; border-radius: 6px; margin-top: 6px; }
details.think {
  margin-bottom: 10px; background: #fbfbfd; border: 1px dashed var(--border-strong);
  border-radius: 8px; padding: 8px 12px;
}
details.think summary {
  cursor: pointer; font-size: 12px; color: var(--muted);
  list-style: none; user-select: none;
}
details.think summary::-webkit-details-marker { display: none; }
details.think summary::before { content: "▸ "; }
details.think[open] summary::before { content: "▾ "; }
details.think .inner {
  margin-top: 8px; font-size: 12.5px; color: #6b7280; white-space: pre-wrap;
  border-left: 2px solid #e3e6ec; padding-left: 10px; line-height: 1.6;
}

/* ---------------- 图表 ---------------- */
.chart-wrap { width: 100%; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ---------------- 提示 ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(10px);
  background: #1f2329; color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }

.tip-box {
  background: var(--warn-soft); border: 1px solid #f5dfb8; color: #8a5a10;
  padding: 10px 13px; border-radius: 8px; font-size: 12.5px; line-height: 1.6;
}
.tip-box.blue { background: var(--primary-soft); border-color: #d5ddff; color: #2c3a80; }

pre.code {
  background: #14161c; color: #d7dae0; padding: 14px 16px; border-radius: 9px;
  overflow: auto; font-family: var(--mono); font-size: 12.3px; line-height: 1.55; margin: 0;
}
pre.code .c { color: #7a808c; }
pre.code .s { color: #9ecbff; }

.row-flex { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mt-14 { margin-top: 14px; }
.mb-0 { margin-bottom: 0; }
.hidden { display: none !important; }

.filter-bar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.filter-bar .input, .filter-bar .select { width: auto; min-width: 140px; height: 31px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 4px 0; font-size: 12.5px; color: var(--muted); }

@media (max-width: 1080px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: relative; }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-item { white-space: nowrap; width: auto; }
  .sidebar-foot { display: none; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
