/* ChatBI 独立页样式 - 克制学术风 */
:root {
  --cb-bg: #fafbfc;
  --cb-surface: #ffffff;
  --cb-border: #e8eaed;
  --cb-border-strong: #d9dde2;
  --cb-text: #1a1a2e;
  --cb-text-secondary: #595959;
  --cb-text-muted: #999;
  --cb-accent: #2b5bff;
  --cb-accent-hover: #1e4add;
  --cb-accent-soft: rgba(43, 91, 255, 0.08);
  --cb-success: #22c55e;
  --cb-danger: #e74c3c;
  --cb-warn: #f59e0b;
  --cb-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --cb-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08);
  --cb-radius: 10px;
  --cb-radius-sm: 6px;
  --cb-sidebar-w: 260px;
  --cb-header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'PingFang SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--cb-bg);
  color: var(--cb-text);
  font-size: 14px;
  line-height: 1.6;
}

/* ========== 顶部 header ========== */
.cb-header {
  height: var(--cb-header-h);
  background: var(--cb-surface);
  border-bottom: 1px solid var(--cb-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.cb-header-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cb-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--cb-text);
}
.cb-logo-icon { font-size: 22px; }
.cb-logo-text { font-size: 17px; font-weight: 700; }
.cb-header-right { display: flex; align-items: center; gap: 16px; }
.cb-nav-link {
  color: var(--cb-text-secondary);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: var(--cb-radius-sm);
  transition: background 0.15s;
}
.cb-nav-link:hover { background: var(--cb-accent-soft); color: var(--cb-accent); }

/* 余额徽章 */
.cb-balance-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: linear-gradient(135deg, #fff 0%, #f0f4ff 100%);
  border: 1px solid var(--cb-accent-soft);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--cb-accent);
  cursor: pointer;
  transition: all 0.15s;
}
.cb-balance-chip:hover { box-shadow: 0 0 0 4px rgba(43, 91, 255, 0.1); transform: translateY(-1px); }
.cb-balance-icon { font-size: 14px; }
.cb-balance-num { font-family: 'SF Mono', 'Menlo', monospace; font-weight: 700; }
.cb-balance-label { font-size: 12px; color: var(--cb-text-secondary); margin-left: 2px; }

/* ========== 主体 ========== */
.cb-main {
  height: calc(100vh - var(--cb-header-h));
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--cb-sidebar-w) 1fr;
  gap: 0;
}

/* ========== 左侧 Sidebar ========== */
.cb-sidebar {
  border-right: 1px solid var(--cb-border);
  background: var(--cb-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cb-sidebar-head { padding: 16px; border-bottom: 1px solid var(--cb-border); }
.cb-sidebar-sessions { flex: 1; overflow-y: auto; padding: 8px; }
.cb-sidebar-empty { color: var(--cb-text-muted); text-align: center; padding: 24px 12px; font-size: 13px; }
.cb-session-item {
  padding: 10px 12px;
  border-radius: var(--cb-radius-sm);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
  position: relative;
}
.cb-session-item:hover { background: var(--cb-bg); }
.cb-session-item.active { background: var(--cb-accent-soft); }
.cb-session-title {
  font-size: 13px;
  color: var(--cb-text);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}
.cb-session-meta {
  font-size: 11px;
  color: var(--cb-text-muted);
  display: flex;
  justify-content: space-between;
}
.cb-session-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--cb-text-muted);
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}
.cb-session-item:hover .cb-session-delete { opacity: 1; }
.cb-session-delete:hover { color: var(--cb-danger); }

.cb-sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--cb-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cb-foot-link {
  color: var(--cb-text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 0;
}
.cb-foot-link:hover { color: var(--cb-accent); }

/* ========== 中间对话区 ========== */
.cb-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--cb-bg);
}
.cb-chat-head {
  padding: 14px 24px;
  background: var(--cb-surface);
  border-bottom: 1px solid var(--cb-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cb-chat-title { font-size: 15px; font-weight: 600; }
.cb-chat-meta { display: flex; align-items: center; gap: 12px; color: var(--cb-text-muted); font-size: 12px; }
.cb-session-cost {
  padding: 4px 10px;
  background: var(--cb-bg);
  border: 1px solid var(--cb-border);
  border-radius: 999px;
  font-family: 'SF Mono', monospace;
}

/* 消息区 */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.cb-welcome {
  max-width: 680px;
  margin: 40px auto;
  text-align: center;
}
.cb-welcome-icon { font-size: 48px; margin-bottom: 12px; }
.cb-welcome h2 { font-size: 24px; margin-bottom: 12px; font-weight: 700; }
.cb-welcome p { color: var(--cb-text-secondary); margin-bottom: 20px; }
.cb-welcome-list {
  list-style: none;
  text-align: left;
  max-width: 400px;
  margin: 0 auto 24px;
  display: inline-block;
}
.cb-welcome-list li { padding: 6px 0; color: var(--cb-text-secondary); }
.cb-welcome-samples { margin-top: 20px; }
.cb-sample-title { font-size: 13px; color: var(--cb-text-muted); margin-bottom: 10px; }
.cb-sample {
  display: inline-block;
  margin: 4px;
  padding: 8px 14px;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius-sm);
  color: var(--cb-text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}
.cb-sample:hover { border-color: var(--cb-accent); color: var(--cb-accent); background: var(--cb-accent-soft); }

/* 消息气泡 */
.cb-msg {
  margin-bottom: 20px;
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}
.cb-msg-user { display: flex; justify-content: flex-end; }
.cb-msg-user .cb-msg-bubble {
  background: var(--cb-accent);
  color: white;
  border-top-right-radius: 4px;
  max-width: 70%;
}
.cb-msg-bot .cb-msg-bubble {
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  color: var(--cb-text);
  border-top-left-radius: 4px;
  max-width: 85%;
}
.cb-msg-bubble {
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--cb-shadow);
}
.cb-msg-bubble pre {
  background: rgba(0, 0, 0, 0.05);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: 'SF Mono', monospace;
  font-size: 12px;
  margin: 8px 0;
}
.cb-msg-bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', monospace;
  font-size: 12.5px;
}
.cb-msg-user .cb-msg-bubble pre,
.cb-msg-user .cb-msg-bubble code {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}
.cb-msg-meta {
  font-size: 11px;
  color: var(--cb-text-muted);
  margin-top: 4px;
  padding: 0 6px;
}
.cb-msg-cost {
  display: inline-block;
  padding: 2px 6px;
  background: var(--cb-accent-soft);
  border-radius: 4px;
  color: var(--cb-accent);
  margin-left: 6px;
  font-family: 'SF Mono', monospace;
}

/* 错误消息 */
.cb-msg-error .cb-msg-bubble {
  background: #fff5f5;
  border-color: #fecaca;
  color: var(--cb-danger);
}

/* 输入区 */
.cb-input-area {
  background: var(--cb-surface);
  border-top: 1px solid var(--cb-border);
  padding: 14px 24px 16px;
}

.cb-upload-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--cb-bg);
  border: 1px dashed var(--cb-border-strong);
  border-radius: var(--cb-radius);
  margin-bottom: 10px;
  font-size: 13px;
}
.cb-upload-hint { color: var(--cb-text-muted); flex: 1; }

.cb-data-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: linear-gradient(90deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #bae6fd;
  border-radius: var(--cb-radius);
  margin-bottom: 10px;
  font-size: 13px;
}
.cb-data-badge {
  padding: 3px 8px;
  background: white;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #0369a1;
}
.cb-data-name { font-weight: 500; color: #0c4a6e; }
.cb-data-dim { color: var(--cb-text-muted); font-family: 'SF Mono', monospace; font-size: 12px; }

.cb-composer {
  background: var(--cb-surface);
  border: 1px solid var(--cb-border-strong);
  border-radius: var(--cb-radius);
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.cb-composer:focus-within { border-color: var(--cb-accent); box-shadow: 0 0 0 3px var(--cb-accent-soft); }
.cb-input {
  width: 100%;
  border: none;
  resize: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  min-height: 40px;
  max-height: 160px;
  padding: 8px 4px;
  background: transparent;
  color: var(--cb-text);
}
.cb-composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid var(--cb-border);
  margin-top: 6px;
}
.cb-model-selector { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--cb-text-muted); }
.cb-select {
  background: transparent;
  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius-sm);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--cb-text-secondary);
  cursor: pointer;
}
.cb-tip {
  font-size: 11px;
  color: var(--cb-text-muted);
  margin-top: 8px;
  text-align: center;
}

/* ========== 按钮 ========== */
.cb-btn {
  padding: 8px 16px;
  border-radius: var(--cb-radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.cb-btn-primary {
  background: var(--cb-accent);
  color: white;
  border-color: var(--cb-accent);
}
.cb-btn-primary:hover { background: var(--cb-accent-hover); border-color: var(--cb-accent-hover); }
.cb-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.cb-btn-ghost {
  background: transparent;
  color: var(--cb-text-secondary);
  border-color: var(--cb-border);
}
.cb-btn-ghost:hover { background: var(--cb-bg); color: var(--cb-accent); border-color: var(--cb-accent); }
.cb-btn-block { width: 100%; justify-content: center; }
.cb-btn-icon {
  background: transparent;
  border: none;
  padding: 4px 8px;
  border-radius: var(--cb-radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--cb-text-muted);
  transition: all 0.15s;
}
.cb-btn-icon:hover { background: var(--cb-bg); color: var(--cb-accent); }
.cb-send-icon { font-size: 16px; margin-left: 2px; }

/* ========== Modal ========== */
.cb-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.cb-modal-inner {
  background: var(--cb-surface);
  border-radius: 14px;
  max-width: 680px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--cb-shadow-lg);
}
.cb-modal-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--cb-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cb-modal-title { font-size: 17px; font-weight: 600; }
.cb-modal-close {
  background: var(--cb-bg);
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--cb-text-muted);
  font-size: 16px;
}
.cb-modal-close:hover { background: var(--cb-border); color: var(--cb-text); }

/* 充值套餐 */
.cb-pricing-hint { padding: 12px 24px 4px; color: var(--cb-text-muted); font-size: 13px; }
.cb-pricing-grid {
  padding: 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  overflow-y: auto;
}
.cb-pkg {
  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.cb-pkg:hover { border-color: var(--cb-accent); transform: translateY(-2px); box-shadow: var(--cb-shadow-lg); }
.cb-pkg-label { font-size: 13px; color: var(--cb-text-secondary); margin-bottom: 8px; }
.cb-pkg-price { font-size: 24px; font-weight: 700; color: var(--cb-accent); }
.cb-pkg-yuan { font-size: 14px; color: var(--cb-text-muted); }
.cb-pkg-points { font-size: 13px; color: var(--cb-text); margin-top: 8px; font-family: 'SF Mono', monospace; }
.cb-pkg-bonus {
  display: inline-block;
  padding: 2px 8px;
  background: #fef3c7;
  color: #92400e;
  border-radius: 4px;
  font-size: 11px;
  margin-top: 6px;
  font-weight: 600;
}
.cb-pricing-foot {
  padding: 12px 24px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-bg);
  text-align: center;
  color: var(--cb-text-secondary);
}

/* 流水 */
.cb-ledger-list { padding: 8px 16px; overflow-y: auto; max-height: 60vh; }
.cb-ledger-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--cb-border);
  font-size: 13px;
}
.cb-ledger-item:last-child { border-bottom: none; }
.cb-ledger-left { flex: 1; }
.cb-ledger-reason { font-weight: 500; color: var(--cb-text); }
.cb-ledger-time { font-size: 11px; color: var(--cb-text-muted); margin-top: 2px; }
.cb-ledger-delta {
  font-family: 'SF Mono', monospace;
  font-weight: 600;
}
.cb-ledger-delta.pos { color: var(--cb-success); }
.cb-ledger-delta.neg { color: var(--cb-danger); }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .cb-main { grid-template-columns: 1fr; }
  .cb-sidebar { display: none; }
}

/* ========== 分析执行相关样式 ========== */
.cb-exec-banner {
  margin-top: 12px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #fef9c3 0%, #fde68a 100%);
  border: 1px solid #f59e0b;
  border-radius: 8px;
  color: #78350f;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cb-exec-err {
  margin-top: 12px;
  padding: 10px 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: var(--cb-danger);
  font-size: 13px;
}
.cb-exec-details {
  margin-top: 12px;
  border: 1px solid var(--cb-border);
  border-radius: 8px;
  background: #fafbfc;
}
.cb-exec-details > summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--cb-text-secondary);
  list-style: none;
  background: var(--cb-bg);
  border-radius: 8px 8px 0 0;
  user-select: none;
}
.cb-exec-details > summary::before {
  content: "▶ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s;
}
.cb-exec-details[open] > summary::before { transform: rotate(90deg); }
.cb-exec-details[open] > summary {
  border-bottom: 1px solid var(--cb-border);
  border-radius: 8px 8px 0 0;
}
.cb-exec-output {
  padding: 12px 16px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.7;
}
.cb-exec-output table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11.5px;
  width: 100%;
}
.cb-exec-output th, .cb-exec-output td {
  border: 1px solid var(--cb-border);
  padding: 4px 8px;
  text-align: left;
}
.cb-exec-output th { background: var(--cb-bg); font-weight: 600; }

/* AI 解读气泡 */
.cb-msg-explain {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%) !important;
  border-color: #93c5fd !important;
  max-width: 85%;
}
.cb-explain-head {
  font-size: 12px;
  color: #1e40af;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(30, 64, 175, 0.15);
}
.cb-explain-body {
  color: var(--cb-text);
  font-size: 14px;
  line-height: 1.75;
}

/* 加载态（3 个点跳动） */
.cb-typing {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
}
.cb-typing span {
  width: 6px;
  height: 6px;
  background: var(--cb-text-muted);
  border-radius: 50%;
  animation: cbBounce 1.2s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cbBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}
