/**
 * ============================================
 * ComputerHub — AI 智能体对话窗口
 * ============================================
 */

/* 遮罩 */
.ch-chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.ch-chat-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* 对话主容器 */
.ch-chat-container {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 460px;
  max-width: 100vw;
  height: 680px;
  max-height: 90vh;
  z-index: 99991;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-right: none;
  border-bottom: none;
  border-radius: var(--radius-lg) 0 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: -8px -4px 40px rgba(0, 0, 0, 0.5), 0 0 60px rgba(0, 212, 255, 0.08);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 0.61, 0.36, 1);
  overflow: hidden;
}

.ch-chat-container.open {
  transform: translateX(0);
}

/* 标题栏 */
.ch-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.08), rgba(124, 58, 237, 0.05));
  flex-shrink: 0;
}

.ch-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ch-chat-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.ch-chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.ch-chat-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.ch-chat-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}

.ch-chat-close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

/* 模型选择器栏 */
.ch-chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.ch-chat-toolbar::-webkit-scrollbar { display: none; }

.ch-model-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 32px 7px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b95b0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 160px;
  transition: border-color 0.2s;
}

.ch-model-select:hover {
  border-color: var(--border-accent);
}

.ch-model-select:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.15);
}

.ch-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  font-family: var(--font-sans);
}

.ch-toolbar-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-accent);
}

.ch-toolbar-btn.active {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--border-accent);
  color: var(--accent-cyan);
}

.ch-toolbar-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.ch-toolbar-spacer {
  flex: 1;
}

.ch-toolbar-clear {
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.ch-toolbar-clear:hover {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.1);
}

/* 消息区域 */
.ch-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.ch-chat-messages::-webkit-scrollbar {
  width: 4px;
}

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

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

/* 欢迎消息 */
.ch-chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 12px;
}

.ch-chat-welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 8px;
}

.ch-chat-welcome h3 {
  font-size: 18px;
  color: var(--text-primary);
  margin: 0;
}

.ch-chat-welcome p {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  max-width: 280px;
  line-height: 1.6;
}

.ch-chat-welcome-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 8px;
}

.ch-chat-welcome-tag {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.ch-chat-welcome-tag:hover {
  border-color: var(--border-accent);
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.08);
}

/* 消息气泡 */
.ch-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: msgSlideIn 0.3s ease-out;
}

@keyframes msgSlideIn {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

.ch-msg-user {
  align-self: flex-end;
}

.ch-msg-assistant {
  align-self: flex-start;
}

.ch-msg-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

.ch-msg-user .ch-msg-bubble {
  background: var(--gradient-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ch-msg-assistant .ch-msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.ch-msg-bubble p {
  margin: 0 0 8px 0;
}

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

/* 代码块 */
.ch-msg-bubble pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  position: relative;
}

.ch-msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-card-hover);
  padding: 2px 6px;
  border-radius: 4px;
}

.ch-msg-bubble pre code {
  background: none;
  padding: 0;
}

.ch-code-lang {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.ch-code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: all 0.2s;
}

.ch-msg-bubble pre:hover .ch-code-copy {
  opacity: 1;
}

.ch-code-copy:hover {
  background: rgba(0, 212, 255, 0.15);
  color: var(--accent-cyan);
  border-color: var(--border-accent);
}

/* 消息时间 */
.ch-msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* 消息角色标签 */
.ch-msg-role {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
  padding: 0 4px;
}

/* 加载动画 */
.ch-msg-loading .ch-msg-bubble {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 16px 24px;
}

.ch-typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s ease-in-out infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* 输入区域 */
.ch-chat-input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.ch-chat-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ch-chat-textarea {
  flex: 1;
  resize: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  padding: 10px 14px;
  line-height: 1.5;
  max-height: 120px;
  min-height: 42px;
  transition: border-color 0.2s;
}

.ch-chat-textarea::placeholder {
  color: var(--text-muted);
}

.ch-chat-textarea:focus {
  outline: none;
  border-color: var(--border-accent);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.08);
}

.ch-chat-upload {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  font-size: 20px;
}

.ch-chat-upload:hover {
  border-color: var(--border-accent);
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.08);
}

.ch-chat-send {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  font-size: 18px;
}

.ch-chat-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}

.ch-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ch-chat-send:active:not(:disabled) {
  transform: scale(0.95);
}

/* 附件预览区 */
.ch-chat-attachment-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ch-chat-attachment-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 100%;
}

.ch-chat-attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  color: var(--text-primary);
}

.ch-chat-attachment-size {
  font-size: 11px;
  color: var(--text-muted);
}

.ch-chat-attachment-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}

.ch-chat-attachment-remove:hover {
  color: var(--danger);
}

/* 消息中的附件 chip */
.ch-msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.ch-msg-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.ch-msg-attachment-chip:hover {
  background: rgba(0, 212, 255, 0.15);
  border-color: var(--accent-cyan);
}

.ch-msg-attachment-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-msg-attachment-size {
  font-size: 11px;
  color: var(--text-muted);
}

/* 工具栏导出按钮 */
.ch-toolbar-export {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  margin-right: 8px;
}

.ch-toolbar-export:hover {
  border-color: var(--border-accent);
  color: var(--accent-cyan);
  background: rgba(0, 212, 255, 0.08);
}

/* 输入提示 */
.ch-chat-input-hint {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  align-items: center;
}

.ch-chat-input-hint span {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* 自定义模型弹窗 */
.ch-custom-model-modal {
  position: fixed;
  inset: 0;
  z-index: 99992;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 20px;
}

.ch-custom-model-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.ch-custom-model-panel {
  width: 420px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(0, 212, 255, 0.1);
  transform: translateY(20px) scale(0.96);
  transition: transform 0.25s ease;
}

.ch-custom-model-modal.open .ch-custom-model-panel {
  transform: translateY(0) scale(1);
}

.ch-custom-model-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.08), rgba(124, 58, 237, 0.05));
}

.ch-custom-model-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-primary);
}

.ch-custom-model-close {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s;
}

.ch-custom-model-close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.ch-custom-model-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ch-custom-model-section h4 {
  margin: 0 0 14px 0;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ch-custom-model-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.ch-custom-model-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.ch-custom-model-field input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ch-custom-model-field input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.12);
}

.ch-custom-model-field input::placeholder {
  color: var(--text-muted);
}

.ch-custom-model-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.ch-custom-model-save {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.ch-custom-model-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 212, 255, 0.3);
}

.ch-custom-model-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px;
  text-align: center;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.ch-custom-model-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: border-color 0.2s;
}

.ch-custom-model-item:hover {
  border-color: var(--border-accent);
}

.ch-custom-model-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ch-custom-model-info strong {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}

.ch-custom-model-info span {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ch-custom-model-delete {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
  color: var(--accent-red);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ch-custom-model-delete:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* 响应式 — 小屏幕全屏 */
@media (max-width: 500px) {
  .ch-chat-container {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .ch-chat-toolbar {
    padding: 8px 14px;
  }

  .ch-model-select {
    min-width: 130px;
    font-size: 12px;
    padding: 6px 28px 6px 10px;
  }

  .ch-chat-messages {
    padding: 14px;
  }
}
