:root {
  --bg-primary: #0E0C15;
  --bg-secondary: #1a1625;
  --bg-tertiary: #1e1b2e;
  --bg-input: #16132a;
  --border-color: #2a2540;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --gradient: linear-gradient(135deg, #89F9E8, #FACB7B);
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

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

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

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.new-chat-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.new-chat-btn:hover { background: var(--accent); }

.sidebar-search {
  padding: 12px 16px;
}
.sidebar-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search input::placeholder { color: var(--text-muted); }

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

.conv-group-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 12px 4px;
  font-weight: 600;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg-tertiary); }
.conv-item.active {
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
  padding-left: 9px;
}
.conv-item-title {
  flex: 1;
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}
.conv-item.active .conv-item-title { color: var(--text-primary); }
.conv-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
  transition: opacity var(--transition);
}
.conv-item:hover .conv-item-delete { opacity: 1; }

/* Main area */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  min-height: 52px;
}
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
}
.header-title {
  font-size: 0.9rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.welcome-greeting {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}
.welcome-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
/* Smart Route Indicator */
.smart-route-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}
.route-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
.route-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Capability Strip (legacy, hidden) */
.capability-strip, .cap-item, .cap-dot { display: none; }

/* Tech Tagline */
.tech-tagline {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.tech-tagline .tag {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(137, 249, 232, 0.2);
  color: rgba(137, 249, 232, 0.85);
  background: rgba(137, 249, 232, 0.04);
  transition: border-color 0.25s ease, background 0.25s ease;
}
.tech-tagline .tag:hover {
  border-color: rgba(137, 249, 232, 0.5);
  background: rgba(137, 249, 232, 0.08);
}
.tech-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  line-height: 1.6;
}

/* Messages */
.messages {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: 12px;
  animation: fadeIn 0.3s ease;
  max-width: 85%;
}
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.message.user .msg-avatar { background: var(--accent); }
.message.assistant .msg-avatar { background: var(--bg-tertiary); border: 1px solid var(--border-color); }

.msg-content {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.925rem;
  line-height: 1.7;
  word-break: break-word;
}
.message.user .msg-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant .msg-content {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.msg-content img {
  max-width: 200px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* Input panel */
.input-panel {
  padding: 12px 20px 20px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  transition: border-color var(--transition);
  box-shadow: var(--shadow);
}
.input-container:focus-within { border-color: var(--accent); }

.attach-btn, .voice-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 10px;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, background 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-btn:hover, .voice-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}
.attach-btn:active, .voice-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.1);
}
.voice-btn.recording {
  color: var(--danger);
  animation: pulse 1s infinite;
  background: rgba(239, 68, 68, 0.1);
}

.textarea-wrap { flex: 1; display: flex; flex-direction: column; }
#chatInput {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.925rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 200px;
  font-family: inherit;
}
#chatInput::placeholder { color: var(--text-muted); }

.image-preview {
  display: none;
  margin-top: 8px;
}
.image-preview.active { display: block; }
.image-preview img {
  max-width: 120px;
  max-height: 80px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.image-preview .remove-img {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview .img-wrap {
  position: relative;
  display: inline-block;
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.send-btn:not(:disabled):hover { background: var(--accent-hover); }
.send-btn:not(:disabled):active { transform: scale(0.92); }

.tool-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-left: 4px;
}
.tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
}
.tool-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.tool-btn[data-active="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tool-icon { font-size: 0.85rem; }

/* Code blocks */
.msg-content pre {
  background: #1a1a2e;
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
  border: 1px solid var(--border-color);
}
.msg-content pre code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.82rem;
  line-height: 1.6;
}
.msg-content code {
  background: rgba(99,102,241,0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}
.msg-content pre code { background: none; padding: 0; }
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover { color: var(--text-primary); border-color: var(--accent); }

/* Markdown content */
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 12px 0 6px;
  font-weight: 600;
}
.msg-content h1 { font-size: 1.3rem; }
.msg-content h2 { font-size: 1.15rem; }
.msg-content h3 { font-size: 1rem; }
.msg-content p { margin: 6px 0; }
.msg-content ul, .msg-content ol { padding-left: 20px; margin: 6px 0; }
.msg-content li { margin: 3px 0; }
.msg-content a { color: var(--accent-hover); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }
.msg-content table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.msg-content th, .msg-content td {
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  text-align: left;
  font-size: 0.85rem;
}
.msg-content th { background: var(--bg-secondary); }
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
}
.sidebar-overlay.active { display: block; }

/* Responsive */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 280px;
    z-index: 100;
    transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
  .hamburger { display: flex; }
  .messages { max-width: 100%; }
  .message { max-width: 92%; }
  .input-panel { padding: 8px 12px 12px; }
}

/* Error message */
.msg-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin: 8px 0;
}

/* Thinking timer */
.thinking-timer {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 4px 0;
  animation: fadeIn 0.3s ease;
}

/* Retry button */
.retry-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--transition);
}
.retry-btn:hover {
  background: var(--accent-hover);
}

/* Deep Thinking Block */
.thinking-block {
  margin-bottom: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(99, 102, 241, 0.04);
}
.thinking-summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  list-style: none;
  transition: background var(--transition);
}
.thinking-summary:hover { background: rgba(99,102,241,0.08); }
.thinking-summary::-webkit-details-marker { display: none; }
.thinking-summary::after {
  content: '▶';
  font-size: 0.6rem;
  margin-left: auto;
  transition: transform 0.2s;
}
.thinking-block[open] .thinking-summary::after { transform: rotate(90deg); }
.thinking-icon { font-size: 1rem; }
.thinking-content {
  padding: 0 14px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.7;
  font-style: italic;
  border-top: 1px solid var(--border-color);
  max-height: 300px;
  overflow-y: auto;
}
.thinking-block.open { animation: thinkPulse 1.5s infinite; }
@keyframes thinkPulse {
  0%, 100% { border-color: var(--border-color); }
  50% { border-color: rgba(99,102,241,0.4); }
}
