/* ---------- AI 对话页面 ---------- */

/* topbar ~89px + workspace padding 28px*2 ≈ 145px */
#ollamaChatView {
  display: grid;
  height: calc(100vh - 145px);
  margin-top: -4px;
}

.chat-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
}

/* ---- 左侧对话列表 ---- */
.chat-sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  overflow: hidden;
}

.chat-sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.chat-new-btn {
  width: 100%;
  justify-content: center;
}

.chat-conv-list {
  overflow-y: auto;
  padding: 8px;
}

.chat-conv-item {
  display: grid;
  gap: 2px;
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
}

.chat-conv-item:hover {
  background: var(--primary-light);
}

.chat-conv-item.active {
  background: var(--primary-light);
  border-color: var(--primary);
}

.chat-conv-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conv-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chat-conv-item-model {
  padding: 1px 6px;
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  border-radius: var(--radius-sm);
  font-size: 11px;
}

.chat-conv-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ---- 右侧聊天主区域 ---- */
.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

/* 顶部栏 */
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.chat-model-select {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  min-width: 180px;
  cursor: pointer;
}

.chat-model-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.chat-title {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-topbar-actions {
  display: flex;
  gap: 4px;
}

.chat-topbar-actions button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
}

.chat-topbar-actions button:hover {
  background: var(--primary-light);
  color: var(--text);
}

/* 消息区域 */
.chat-messages {
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg);
}

.chat-empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--muted);
  text-align: center;
}

.chat-empty-hint svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

.chat-empty-hint p {
  margin: 0;
  font-size: 14px;
}

/* 消息气泡 */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: chatMsgIn 0.2s ease-out;
}

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

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

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

.chat-msg-role {
  font-size: 11px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.chat-msg.user .chat-msg-role {
  text-align: right;
}

.chat-msg-content {
  padding: 10px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user .chat-msg-content {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-msg.assistant .chat-msg-content {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-msg-content code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: "SF Mono", "Cascadia Code", monospace;
}

.chat-msg-content pre {
  background: rgba(0, 0, 0, 0.04);
  padding: 12px 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
}

.chat-msg-content pre code {
  background: none;
  padding: 0;
}

.chat-msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

.chat-msg.user .chat-msg-time {
  text-align: right;
}

/* 流式闪烁光标 */
.chat-msg.streaming .chat-msg-content::after {
  content: "|";
  animation: blink 0.8s infinite;
  color: var(--primary);
}

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

/* 输入区 */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.chat-input-area textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.5;
  resize: none;
  min-height: 40px;
  max-height: 160px;
}

.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.chat-input-area textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-btn {
  padding: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), opacity var(--transition);
}

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

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

.chat-send-btn svg {
  width: 18px;
  height: 18px;
}

/* 加载动画 */
.chat-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
}

.chat-loading-dots {
  display: flex;
  gap: 4px;
}

.chat-loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: dotPulse 1.2s infinite ease-in-out;
}

.chat-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* 模型选项分组样式 */
.chat-model-select optgroup {
  font-weight: 600;
  color: var(--text-secondary);
}

.chat-model-select option {
  font-weight: 400;
  padding: 4px 8px;
}
