:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #3b82f6;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #eef0f4;
  --text: #1f2937;
  --muted: #6b7280;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.layout { display: flex; min-height: 100vh; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 220px;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #cbd5e1;
  display: flex; flex-direction: column;
  position: fixed; height: 100vh;
  box-shadow: 2px 0 16px rgba(0, 0, 0, .12);
}
.sidebar .logo {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px; font-size: 17px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.sidebar .logo img { width: 28px; height: 28px; border-radius: 6px; }
.sidebar .nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar .nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin-bottom: 4px;
  color: #94a3b8; text-decoration: none; font-size: 14px;
  cursor: pointer; border-radius: 10px;
  transition: all .18s ease;
}
.sidebar .nav a .ico { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar .nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar .nav a.active {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, .35);
}
.sidebar .foot { padding: 16px 20px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 13px; }
.sidebar .foot a { color: #94a3b8; text-decoration: none; display: block; padding: 6px 0; cursor: pointer; transition: color .15s; }
.sidebar .foot a:hover { color: #fff; }

/* ---------- 主区域 ---------- */
.main { flex: 1; margin-left: 220px; padding: 32px 36px; }
.main h2 {
  font-size: 22px; margin-bottom: 22px; font-weight: 700;
  position: relative; padding-left: 14px;
}
.main h2::before {
  content: ""; position: absolute; left: 0; top: 3px; bottom: 3px;
  width: 4px; border-radius: 2px;
  background: linear-gradient(#2563eb, #3b82f6);
}

/* ---------- 统计卡片 ---------- */
.cards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px; margin-bottom: 26px;
}
.card {
  background: var(--card); border-radius: 14px; padding: 22px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
  border: 1px solid var(--border);
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(15, 23, 42, .1); }
.card .num {
  font-size: 32px; font-weight: 800;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.card .label { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--card); border-radius: 14px; padding: 22px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
  border: 1px solid var(--border);
}

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #f0f2f5; }
th {
  color: #64748b; font-weight: 600; background: #f8fafc;
  font-size: 13px; letter-spacing: .3px;
}
tbody tr { transition: background .15s; }
tbody tr:hover td { background: #f8fafc; }
td code {
  background: #f1f5f9; padding: 2px 6px; border-radius: 5px;
  font-size: 12px; color: #334155;
}

/* ---------- 按钮 ---------- */
button, .btn {
  background: var(--primary); color: #fff; border: none; border-radius: 8px;
  padding: 8px 16px; font-size: 13px; cursor: pointer;
  transition: all .15s ease;
}
button:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(37, 99, 235, .28); }
button.ghost { background: #fff; color: #374151; border: 1px solid #d1d5db; }
button.ghost:hover { background: #f3f4f6; box-shadow: none; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; box-shadow: 0 4px 12px rgba(220, 38, 38, .28); }
button.sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }

/* ---------- 输入框 ---------- */
input, textarea, select {
  border: 1px solid #d1d5db; border-radius: 8px; padding: 9px 12px;
  font-size: 14px; font-family: inherit; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
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; }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }

/* ---------- 标签 ---------- */
.tag { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.tag.pending, .tag.replied { background: #fef3c7; color: #b45309; }
.tag.confirmed, .tag.on { background: #d1fae5; color: #047857; }
.tag.open { background: #dbeafe; color: #1d4ed8; }
.tag.closed, .tag.off, .tag.cancelled { background: #e5e7eb; color: #6b7280; }

.muted { color: var(--muted); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 20px; right: 20px;
  background: #0f172a; color: #fff; padding: 13px 20px; border-radius: 10px;
  display: none; z-index: 999; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

/* ---------- 表单布局 ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: #374151; margin-bottom: 7px; font-weight: 500; }

.section-title { font-size: 15px; font-weight: 700; margin: 22px 0 12px; color: #111827; }

.detail {
  white-space: pre-wrap; background: #f8fafc; padding: 14px; border-radius: 10px;
  font-size: 14px; border: 1px solid #eef0f4;
}

/* ---------- 调用日志详情：JSON 展示 + 键值表 ---------- */
pre.codebox {
  white-space: pre-wrap; word-break: break-word;
  background: #0f172a; color: #e2e8f0;
  padding: 16px; border-radius: 10px;
  font-size: 13px; line-height: 1.6;
  max-height: 460px; overflow: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
table.kv th { width: 110px; white-space: nowrap; vertical-align: top; text-align: left; color: #6b7280; }
table.kv td { word-break: break-all; }

/* ---------- 类型规则：多模型优先级 ---------- */
.rule-ais { display: flex; flex-direction: column; gap: 6px; }
.rule-ai-slot { display: flex; align-items: center; gap: 6px; }
.rule-ai-slot .prio {
  flex-shrink: 0; min-width: 26px; text-align: center;
  font-size: 11px; font-weight: 700; color: #fff;
  background: var(--primary); border-radius: 6px; padding: 3px 0;
}
