/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --bg: #f8fafc;
  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --user-msg-bg: #2563eb;
  --user-msg-text: #ffffff;
  --bot-msg-bg: #f1f5f9;
  --success: #10b981;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 12px;
  --transition: 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* === Layout === */
.app-container {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition);
  z-index: 100;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition);
}

.new-chat-btn:hover {
  background: rgba(255,255,255,0.14);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
}

.cap-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 12px;
}

.cap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cap-tag {
  padding: 6px 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 20px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  transition: background var(--transition);
}

.cap-tag:hover {
  background: rgba(255,255,255,0.12);
}

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

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255,255,255,0.5);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

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

/* === Chat Area === */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.menu-toggle:hover {
  background: var(--bot-msg-bg);
}

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

.chat-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-left: auto;
}

/* === Messages === */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Welcome */
.welcome-message {
  text-align: center;
  padding: 60px 20px 40px;
  max-width: 640px;
  margin: 0 auto;
}

.welcome-avatar {
  font-size: 64px;
  margin-bottom: 20px;
}

.welcome-message h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-message p {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.welcome-hint {
  margin-top: 8px;
  font-size: 14px !important;
  opacity: 0.7;
}

/* Suggestions */
.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 32px;
}

.suggestion-btn {
  padding: 14px 18px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.suggestion-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.12);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.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: 18px;
  flex-shrink: 0;
}

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

.message.bot .message-avatar {
  background: #f0abfc;
  color: #701a75;
}

.message-content {
  max-width: 72%;
}

.message.user .message-content {
  order: -1;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  line-height: 1.65;
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
  border-bottom-right-radius: 4px;
}

.message.bot .message-bubble {
  background: var(--bot-msg-bg);
  border-bottom-left-radius: 4px;
}

.message-bubble p {
  margin-bottom: 10px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble strong {
  font-weight: 600;
}

.message-bubble ul, .message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin-bottom: 4px;
}

.message-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
}

.message-bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  font-family: 'SF Mono', 'Monaco', 'Menlo', monospace;
  line-height: 1.5;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

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

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

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* === Input Area === */
.input-area {
  padding: 16px 24px 20px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 4px 4px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.user-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 0;
  font-size: 15px;
  color: var(--text);
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 1.5;
  max-height: 150px;
}

.user-input::placeholder {
  color: #94a3b8;
}

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

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

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

.send-btn.loading {
  background: #94a3b8;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.input-footer {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

.input-footer span {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* === Error Message === */
.error-bubble {
  background: #fef2f2 !important;
  color: #dc2626 !important;
  border: 1px solid #fecaca;
}

/* === Responsive === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: flex;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .messages {
    padding: 16px;
  }

  .message-content {
    max-width: 85%;
  }

  .welcome-message {
    padding: 40px 16px 32px;
  }

  .welcome-message h2 {
    font-size: 22px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .input-area {
    padding: 12px 16px 16px;
  }

  .chat-subtitle {
    display: none;
  }
}
