/* 杆杆响智慧助手 — 聊天界面样式 */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* 继承图谱页面的深色主题 */
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-card: #0f3460;
  --text: #e6e6e6;
  --text-muted: #a0a0b0;
  --accent: #e94560;
  --accent-light: #ff6b81;
  --border: #2a2a4a;
  
  /* 聊天气泡颜色 */
  --user-bubble: #2563eb;
  --user-bubble-text: #ffffff;
  --ai-bubble: #252545;
  --ai-bubble-text: #e6e6e6;
  
  /* 意图标签颜色 */
  --intent-qa: #10b981;
  --intent-bd: #f59e0b;
  --intent-ops: #8b5cf6;
  --intent-office: #3b82f6;
}

html, body { 
  height: 100%; 
  font-family: -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  overflow: hidden; 
}

/* ===== Header / Navigation ===== */
#header {
  display: flex; 
  align-items: center; 
  justify-content: space-between;
  height: 52px; 
  padding: 0 16px;
  background: var(--bg-surface); 
  border-bottom: 1px solid var(--border);
}

#header h1 { 
  font-size: 16px; 
  font-weight: 600; 
  white-space: nowrap; 
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-nav { display: flex; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.nav-link {
  padding: 8px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.2s;
}
.nav-link:hover { color: var(--text); background: var(--bg-card); }
.nav-link.active { 
  color: var(--accent); 
  background: rgba(233, 69, 96, 0.15); 
  font-weight: 500;
}

/* ===== Buttons ===== */
button {
  cursor: pointer; 
  border: none; 
  border-radius: 4px;
  padding: 6px 12px; 
  font-size: 13px; 
  transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-ghost { 
  background: transparent; 
  color: var(--text-muted); 
  padding: 4px 8px;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-card); }
.btn-sm { font-size: 12px; }
.btn-icon { 
  background: var(--bg-card); 
  color: var(--text); 
  font-size: 16px; 
  width: 36px; 
  height: 36px; 
  padding: 0; 
  display: flex; 
  align-items: center; 
  justify-content: center;
  border-radius: 6px;
}
.btn-icon:hover { background: var(--border); }

/* ===== Main Layout ===== */
#main { 
  display: flex; 
  height: calc(100vh - 52px); 
}

/* ===== Sidebar ===== */
#sidebar {
  width: 260px; 
  min-width: 260px; 
  padding: 16px;
  background: var(--bg-surface); 
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: margin-left 0.3s ease;
}
#sidebar.collapsed {
  margin-left: -260px;
}

.sidebar-section { 
  margin-bottom: 24px; 
}
.sidebar-section h3 { 
  font-size: 12px; 
  color: var(--text-muted); 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  margin-bottom: 12px; 
}

/* Role Selector */
.role-selector { 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
}
.role-option {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.role-option input { 
  display: none; 
}
.role-label {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid transparent;
  transition: all 0.2s;
}
.role-option input:checked + .role-label {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}
.role-option:hover .role-label {
  border-color: var(--border);
}

/* Preset List (sidebar) */
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.preset-item {
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.preset-item:hover {
  background: var(--border);
}
.preset-item .icon {
  font-size: 16px;
}

/* History List */
.history-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.history-item {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s;
}
.history-item:hover {
  background: var(--bg-card);
  color: var(--text);
}
.history-empty {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

/* ===== Chat Container ===== */
#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

/* ===== Messages Area ===== */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
#messages::-webkit-scrollbar {
  width: 6px;
}
#messages::-webkit-scrollbar-track {
  background: transparent;
}
#messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
#messages::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeIn 0.5s ease;
}
.welcome-icon {
  font-size: 64px;
  margin-bottom: 16px;
}
.empty-state h2 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 8px;
}
.welcome-subtitle {
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 32px;
}

/* Preset Cards (empty state) */
.preset-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  max-width: 600px;
  width: 100%;
  padding: 0 20px;
}
.preset-card {
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}
.preset-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.preset-card .icon {
  font-size: 24px;
  margin-bottom: 8px;
}
.preset-card .text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

/* ===== Message Bubbles ===== */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: slideIn 0.3s ease;
}
.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(--user-bubble);
}
.message.ai .message-avatar {
  background: var(--bg-card);
}

.message-content {
  max-width: 70%;
  min-width: 100px;
}

/* Intent Tag */
.intent-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 12px;
  margin-bottom: 6px;
  font-weight: 500;
}
.intent-tag.qa { background: rgba(16, 185, 129, 0.2); color: var(--intent-qa); }
.intent-tag.bd { background: rgba(245, 158, 11, 0.2); color: var(--intent-bd); }
.intent-tag.ops { background: rgba(139, 92, 246, 0.2); color: var(--intent-ops); }
.intent-tag.office { background: rgba(59, 130, 246, 0.2); color: var(--intent-office); }

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
}
.message.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
}
.message.ai .message-bubble {
  background: var(--ai-bubble);
  color: var(--ai-bubble-text);
  border-bottom-left-radius: 4px;
}

/* Markdown content styling */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 12px 0 8px 0;
  font-weight: 600;
}
.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }

.message-bubble p {
  margin: 8px 0;
}
.message-bubble ul, .message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}
.message-bubble li {
  margin: 4px 0;
}
.message-bubble code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 13px;
}
.message-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.message-bubble pre code {
  background: none;
  padding: 0;
}
.message-bubble a {
  color: var(--accent-light);
  text-decoration: none;
}
.message-bubble a:hover {
  text-decoration: underline;
}
.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding-left: 12px;
  color: var(--text-muted);
}
.message-bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  width: 100%;
}
.message-bubble th, .message-bubble td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.message-bubble th {
  background: var(--bg-card);
}

/* Sources */
.message-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.message-sources-title {
  margin-bottom: 4px;
}
.source-item {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-card);
  border-radius: 4px;
  margin: 2px 4px 2px 0;
  font-size: 11px;
}

/* ===== Input Area ===== */
#input-area {
  padding: 16px 20px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 12px;
  transition: border-color 0.2s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
}

#user-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}
#user-input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-send:hover {
  background: var(--accent-light);
}
.btn-send:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.input-hint {
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}

/* Typing Indicator */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.typing-indicator.hidden {
  display: none;
}
.typing-indicator .dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0s; }

/* Streaming Cursor */
.streaming-cursor {
  display: inline-block;
  color: var(--accent);
  animation: blink 0.8s infinite;
  margin-left: 2px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { 
    opacity: 0; 
    transform: translateY(10px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    height: calc(100vh - 52px);
    z-index: 100;
    transform: translateX(-100%);
  }
  #sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .message-content {
    max-width: 85%;
  }
  
  .preset-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .header-nav {
    display: none;
  }
  
  #header h1 {
    font-size: 14px;
  }
  
  .empty-state h2 {
    font-size: 20px;
  }
  
  .welcome-icon {
    font-size: 48px;
  }
}
