/* 知氏个人助手 - 样式表 */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg: #f8fafc;
  --sidebar-bg: #1e293b;
  --sidebar-text: #e2e8f0;
  --chat-bg: #ffffff;
  --message-user: #2563eb;
  --message-assistant: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  height: 100vh; /* fallback */
  overflow: hidden;
}

.app {
  display: flex;
  height: 100dvh;
  height: 100vh; /* fallback */
}

/* 侧边栏 */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h1 {
  font-size: 18px;
  margin-bottom: 12px;
}

.new-chat-btn {
  width: 100%;
  padding: 10px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.new-chat-btn:hover {
  background: var(--primary-hover);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.conversation-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s;
}

.conversation-item:hover,
.conversation-item.active {
  background: rgba(255,255,255,0.1);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.status-dot.disconnected {
  background: #ef4444;
}

.status-dot.connecting {
  background: #f59e0b;
}

/* 主聊天区 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: white;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
}

.chat-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

.welcome-message {
  text-align: center;
  padding: 60px 20px;
  max-width: 600px;
  margin: 0 auto;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.welcome-message h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.welcome-message p {
  color: var(--text-muted);
  margin-bottom: 32px;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.suggestion-card {
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  transition: all 0.2s;
}

.suggestion-card:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

/* 消息气泡 */
.message {
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--primary);
  color: white;
}

.message.assistant .message-avatar {
  background: #f1f5f9;
}

.message-content {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  max-width: 70%;
}

.message.user .message-content {
  background: var(--message-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--message-assistant);
  border-bottom-left-radius: 4px;
}

.message-content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
}

.message-content table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
  font-size: 13px;
}

.message-content th,
.message-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.message-content th {
  background: #f8fafc;
  font-weight: 600;
}

/* SQL 展示 */
.sql-block {
  background: #1e293b;
  color: #94a3b8;
  padding: 10px 14px;
  border-radius: 8px;
  font-family: 'Fira Code', monospace;
  font-size: 12px;
  margin: 8px 0;
  overflow-x: auto;
}

.sql-block .keyword {
  color: #60a5fa;
}

/* 思考中动画 */
.thinking-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.thinking-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite;
}

.thinking-indicator span:nth-child(2) { animation-delay: 0.2s; }
.thinking-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

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

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
}

#messageInput {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 120px;
  font-family: inherit;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 响应式 */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .suggestions {
    grid-template-columns: 1fr;
  }
  .message-content {
    max-width: 85%;
  }
  .chat-messages {
    padding: 16px;
  }
  .chat-input-area {
    padding: 12px 16px;
  }
  /* 移动端输入框固定底部 */
  .chat-main {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}
