:root {
  --bg: #f5f7fa;
  --panel-bg: #ffffff;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --text: #1e293b;
  --muted: #64748b;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-width: 260px;
  --ai-panel-width: 320px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

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

.topbar {
  height: 56px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 32px;
  flex-shrink: 0;
}

.logo { font-weight: 700; font-size: 18px; color: var(--primary); }

.nav { display: flex; gap: 24px; }
.nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  padding: 4px 0;
  cursor: pointer;
}
.nav a.active, .nav a:hover { color: var(--primary); border-bottom: 2px solid var(--primary); }

.user { margin-left: auto; font-size: 14px; color: var(--muted); }

.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ====== 面板系统 ====== */
.panel { display: none !important; }
.panel.active { display: flex !important; }

.panel-container {
  flex: 1;
  background: var(--panel-bg);
  margin: 16px;
  border-radius: 12px;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.panel-header h2 { margin: 0; font-size: 20px; }
.stats { font-size: 13px; color: var(--muted); }

/* 数据表格 */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.data-table tr:hover td { background: #f8fafc; }

.badge.status-open { background: #dbeafe; color: #1e40af; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.badge.status-closed { background: #f1f5f9; color: #64748b; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.badge.pri-normal { background: #f1f5f9; color: #64748b; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.badge.pri-high { background: #fef3c7; color: #92400e; padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.badge.pri-urgent { background: #fee2e2; color: #991b1b; padding: 2px 8px; border-radius: 4px; font-size: 12px; }

/* 知识库面板 */
.kb-search-bar, .kb-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.kb-toolbar input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}

.kb-toolbar select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  min-width: 130px;
}

.kb-entry-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.kb-entry-card:hover { border-color: var(--primary); }

.kb-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.kb-entry-cat {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eff6ff;
  color: var(--primary);
}

.kb-entry-content {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 8px;
}


.kb-batch-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}

.kb-batch-bar label { cursor: pointer; display: flex; align-items: center; gap: 4px; }

.kb-entry-checkbox { width: 18px; height: 18px; cursor: pointer; margin-top: 1px; flex-shrink: 0; }

.kb-entry-footer {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--muted);
}

.kb-result-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
  background: #fafafa;
}

.kb-result-score {
  font-size: 11px;
  color: var(--primary);
  margin-bottom: 6px;
  font-weight: 500;
}

.kb-result-card .source {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}

/* 数据看板 */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

/* 空状态 */
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
}

.empty-state p { margin: 4px 0; }

/* 快速测试按钮 */
.quick-demo {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.quick-demo button {
  width: 100%;
  padding: 10px;
  font-size: 13px;
}

.session-list {
  width: var(--sidebar-width);
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.session-header {
  padding: 12px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.search {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}

#newSessionBtn {
  width: 32px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
}

.tabs {
  display: flex;
  padding: 8px;
  gap: 6px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { background: #eff6ff; color: var(--primary); font-weight: 500; }

.list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
}

.session-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.session-item:hover, .session-item.active { background: #f8fafc; }

.session-item .title {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}

.session-item .meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.session-item .badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e2e8f0;
  color: var(--muted);
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.chat-header {
  height: 56px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-weight: 500;
}

.status { font-size: 12px; color: var(--muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}

.message.customer { align-self: flex-start; background: white; border: 1px solid var(--border); }
.message.agent { align-self: flex-end; background: #dbeafe; }
.message.ai { align-self: flex-start; background: #f0fdf4; border: 1px solid #bbf7d0; }

.message .role-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.input-area {
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  padding: 16px 20px;
}

.input-area textarea {
  width: 100%;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  resize: none;
}

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

button {
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-size: 14px;
  cursor: pointer;
}

button:hover { background: var(--primary-hover); }
button.secondary { background: #f1f5f9; color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #e2e8f0; }

.ai-panel {
  width: var(--ai-panel-width);
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.panel-title {
  height: 56px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 600;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.profile p { margin: 4px 0; font-size: 13px; color: var(--text); }

#aiAnswers { display: flex; flex-direction: column; gap: 10px; }

.ai-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  background: #fafafa;
  cursor: pointer;
}

.ai-card:hover { border-color: var(--primary); }

.ai-card .score {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 6px;
}

.score.high { background: #dcfce7; color: #166534; }
.score.mid { background: #fef3c7; color: #92400e; }
.score.low { background: #f1f5f9; color: var(--muted); }

.ai-card .source { font-size: 11px; color: var(--muted); margin-top: 6px; }
.ai-card .actions { margin-top: 8px; }
.ai-card .actions button { padding: 4px 10px; font-size: 12px; }

.quick-actions { display: flex; flex-direction: column; gap: 8px; }
.quick-actions button { background: #f8fafc; color: var(--text); border: 1px solid var(--border); text-align: left; }
.quick-actions button:hover { background: #eff6ff; }

.hidden { display: none !important; }

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: white;
  border-radius: 12px;
  width: 420px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-content h3 { margin: 0 0 8px; }
.modal-content label { font-size: 13px; color: var(--muted); }
.modal-content input, .modal-content select, .modal-content textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
.modal-content textarea { min-height: 80px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
