/* ========== 运营对话页面样式（第四期新增） ========== */

/* 覆盖首页 .main-content 的 flex 居中布局，改为列式块级 */
.main-content {
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 24px 32px;
  align-items: initial;
  justify-content: initial;
  height: calc(100vh - 60px); /* 减去 header 高度 */
  box-sizing: border-box;
}

/* 顶部信息条 */
.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 16px;
  flex-shrink: 0;
}

.chat-title-group {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.chat-subtitle {
  font-size: 13px;
  color: var(--color-text-light);
}

.usage-badge {
  flex-shrink: 0;
  padding: 6px 12px;
  background-color: #eef2ff;
  color: var(--color-primary);
  border-radius: 16px;
  font-size: 13px;
  white-space: nowrap;
}

.usage-badge strong {
  font-weight: 700;
}

/* 使用接近上限时的样式 */
.usage-badge.usage-warn {
  background-color: #fef3c7;
  color: #92400e;
}

.usage-badge.usage-limit {
  background-color: #fee2e2;
  color: #b91c1c;
}

/* 错误提示条 */
.chat-error-bar {
  padding: 10px 14px;
  background-color: #fee2e2;
  color: #b91c1c;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

/* 对话区 */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-color: #fafbfc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
}

/* 消息行 */
.msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}

.msg-user {
  flex-direction: row-reverse;
}

/* 头像/标签 */
.msg-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.msg-user .msg-avatar {
  background-color: #6b7280;
}

/* 气泡 */
.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: calc(100% - 50px);
}

.msg-assistant .msg-bubble {
  background-color: #ffffff;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-top-left-radius: 4px;
}

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

/* 加载气泡（专家正在输入） */
.msg-typing .msg-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #9ca3af;
  animation: typing 1.4s infinite ease-in-out;
}

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

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

/* 输入区 */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  background-color: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  padding: 8px 4px;
  max-height: 120px;
  min-height: 24px;
}

.chat-input::placeholder {
  color: #9ca3af;
}

.chat-input:disabled {
  background-color: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
}

.chat-send-btn {
  flex-shrink: 0;
  padding: 8px 20px;
  min-height: 40px;
  font-size: 14px;
}

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

/* 超限提示 */
.chat-limit-tip {
  margin-top: 8px;
  padding: 10px 14px;
  background-color: #fef3c7;
  color: #92400e;
  border-radius: var(--radius);
  font-size: 13px;
  text-align: center;
}

/* 输入区禁用状态（超限） */
.chat-input-bar.disabled {
  background-color: #f9fafb;
  opacity: 0.7;
}

/* ========== Markdown 渲染样式（第六期新增） ========== */
.msg-bubble .md-p {
  margin: 0 0 8px 0;
  line-height: 1.6;
}

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

.msg-bubble .md-h2,
.msg-bubble .md-h3,
.msg-bubble .md-h4 {
  margin: 12px 0 6px 0;
  font-weight: 600;
  line-height: 1.4;
}

.msg-bubble .md-h2 {
  font-size: 16px;
}

.msg-bubble .md-h3 {
  font-size: 15px;
}

.msg-bubble .md-h4 {
  font-size: 14px;
  color: var(--color-text-light, #6b7280);
}

.msg-bubble .md-list {
  margin: 6px 0 8px 0;
  padding-left: 22px;
}

.msg-bubble .md-list li {
  margin-bottom: 4px;
  line-height: 1.6;
}

.msg-bubble .md-list li:last-child {
  margin-bottom: 0;
}

.msg-bubble .md-inline-code {
  background-color: #f3f4f6;
  color: #be185d;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
}

.msg-bubble .md-code-block {
  background-color: #1f2937;
  color: #e5e7eb;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.msg-bubble .md-code-block code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.msg-bubble strong {
  font-weight: 600;
  color: #111827;
}

.msg-bubble em {
  font-style: italic;
}

.msg-bubble .md-error {
  color: #dc2626;
  font-size: 13px;
}

/* 响应式 */
@media (max-width: 640px) {
  .main-content {
    padding: 16px 12px 20px;
    height: calc(100vh - 56px);
  }

  .chat-header {
    flex-direction: column;
    gap: 8px;
  }

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

  .msg-bubble {
    max-width: calc(100% - 46px);
    font-size: 13px;
  }

  .chat-window {
    padding: 12px;
  }
}
