/*!
 * 智能对话室 —— 前台「AI 智能助手」与后台「智能对话室」共用的样式
 *
 * 以前台/后台任意一方引入都能正常工作：
 * 依赖的 CSS 变量（--wp-*）在这里做了兜底定义，
 * 避免在没定义这些变量的页面（如前台）出现样式错乱。
 *
 * 消息样式：纯气泡（无头像），自己的消息靠右、他人/AI 靠左。
 */

:root {
  --wp-primary: #0f766e;
  --wp-primary-dark: #115e59;
  --wp-primary-soft: #14b8a6;
  --wp-accent: #00c250;
  --wp-bg: #f1f5f4;
  --wp-card: #ffffff;
  --wp-text: #1f2937;
  --wp-text-soft: #6b7280;
  --wp-border: #e5ecea;
  --wp-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --wp-radius: 14px;
}

/* ============ 消息列表 ============ */
.chat-discussion {
  background: #f2f6f5;
  padding: 16px 14px;
  overflow-y: auto;
  scroll-behavior: smooth;
  flex: 1;
  min-height: 0;
}
.chat-discussion::-webkit-scrollbar { width: 8px; }
.chat-discussion::-webkit-scrollbar-thumb {
  background: #c9d8d4;
  border-radius: 8px;
}
.chat-discussion::-webkit-scrollbar-thumb:hover { background: #aec4bf; }

/* ============ 气泡布局（无头像） ============ */
.chat-message {
  display: flex;
  margin-bottom: 12px;
  animation: wpFadeIn .25s ease;
}
@keyframes wpFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* 左：他人 / AI / 系统　右：自己 */
.chat-message.left  { justify-content: flex-start; }
.chat-message.right { justify-content: flex-end; }

/* 气泡本体 */
.chat-message .message {
  max-width: 82%;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--wp-border);
  border-radius: 4px 14px 14px 14px;
  padding: 9px 13px;
  position: relative;
  box-shadow: 0 2px 8px rgba(16, 24, 40, .05);
  word-break: break-word;
}

/* 自己的气泡：靠右，浅绿底 */
.chat-message.right .message {
  background: #e6f5f2;
  border-color: #c5e5df;
  border-radius: 14px 4px 14px 14px;
}

/* 气泡上方的「用户名 + 时间 + 类型标签」一行 */
.chat-message .message .message-author {
  font-size: 12px;
  font-weight: 600;
  color: var(--wp-text);
  margin-right: 8px;
}
.chat-message.right .message .message-author { color: #0f766e; }
.message-date {
  font-size: 11px;
  color: #9aa3b2;
}

/* 气泡正文 */
.message-content {
  display: block;
  margin-top: 4px;
  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.7;
  color: #4b5563;
  overflow-x: hidden;
  white-space: pre-wrap;
}
.chat-message.right .message-content { color: #14524c; }
.message-content.console-log {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11.5px;
  color: #374151;
}

/* 欢迎语消息（打开 AI 助手时的问候） */
.chat-message.welcome .message {
  background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
  border-color: #bbf7d0;
}
.chat-message.welcome .message .message-author { color: #15803d; }
.chat-message.welcome .message-content { color: #166534; }

/* 错误日志消息（仅 root 可见） */
.chat-message.system .message {
  background: #fff7f5;
  border-color: #ffd9cf;
  box-shadow: 0 2px 8px rgba(239, 68, 68, .08);
}
.chat-message.system .message .message-author { color: #b91c1c; }
.msg-type-tag[data-type="error"] { background: #fee2e2; color: #b91c1c; }
.message-content.error-log {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #7f1d1d;
  max-height: 260px;
  overflow: auto;
  margin-top: 6px;
}
.message-content.error-log pre {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 类型标签 */
.msg-type-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 6px;
  vertical-align: 1px;
}
.msg-type-tag[data-type="public"]  { background: #eef1f6; color: #64748b; }
.msg-type-tag[data-type="private"] { background: #fff3e0; color: #e65100; }
.msg-type-tag[data-type="ai"]      { background: #d9f2ef; color: #0f766e; }
.msg-type-tag[data-type="vip"]     { background: #fdeecd; color: #b45309; }

/* 进度提示（AI 执行进度）：瞬时状态，只保留一个节点并原地更新 */
.progress-hint {
  color: #9aa3b2 !important;
  font-style: italic;
  font-size: 0.92em;
}
.progress-msg .message {
  background: transparent;
  border: 1px dashed #e5ecea;
  border-radius: 12px;
  padding: 8px 12px;
  animation: wpFadeIn .2s ease;
}
.progress-msg .message-author,
.progress-msg .message-date {
  opacity: .75;
}

/* ============ 输入区 ============ */
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border-top: 1px solid var(--wp-border);
  background: #fbfdfc;
  padding: 12px 14px;
  flex-shrink: 0;
}
.chat-input-box {
  flex: 1;
  min-width: 0;
  background: #fff;
  border: 1px solid var(--wp-border);
  border-radius: 12px;
  padding: 0 12px;
  transition: border-color .18s, box-shadow .18s;
}
.chat-input-box:focus-within {
  border-color: var(--wp-primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .10);
}
.chat-input-wrap.locked .chat-input-box {
  background: #f1f5f4;
  border-color: #dde5e2;
}
.chat-input-box textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  min-height: 44px;
  padding: 12px 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--wp-text);
  font-family: inherit;
  max-height: 150px;
  background: transparent;
}
.chat-input-box textarea::placeholder { color: #9aa3b2; }

/* 字数统计 */
.chat-input-count {
  flex-shrink: 0;
  align-self: flex-end;
  font-size: 11px;
  color: #9aa3b2;
  margin: 0 4px 12px 0;
  font-variant-numeric: tabular-nums;
}
.chat-input-count.warn { color: #f59e0b; }
.chat-input-count.over { color: #ef4444; }

.chat-send-btn {
  flex-shrink: 0;
  align-self: stretch;
  min-height: 44px;
  padding: 0 26px;
  background: linear-gradient(135deg, var(--wp-primary), var(--wp-primary-soft));
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .18s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.chat-send-btn:hover { filter: brightness(1.08); }
.chat-send-btn:active { filter: brightness(.94); transform: scale(.97); }
.chat-send-btn.empty,
.chat-send-btn.idle {
  background: #ccd9d5;
  cursor: not-allowed;
  filter: none;
}
.chat-send-btn.locked,
.chat-send-btn:disabled {
  background: #ccd9d5 !important;
  cursor: not-allowed;
  filter: none;
}

/* ============ 输入提示条 ============ */
.chat-input-tip {
  padding: 6px 16px 10px;
  font-size: 11.5px;
  color: #9aa3b2;
  background: #fbfdfc;
  border-top: 1px dashed #eef2f1;
  flex-shrink: 0;
}
.chat-input-tip kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  font-size: 11px;
  font-family: Consolas, "Courier New", monospace;
  background: #fff;
  border: 1px solid var(--wp-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--wp-text-soft);
}

/* ============ 点击消息：切换成私聊（/to 用户名） ============ */
/* 可回复的消息加上「可点击」样式 */
.chat-message[data-replyable="1"] { cursor: pointer; }
.chat-message[data-replyable="1"]:hover .message {
  border-color: var(--wp-primary-soft);
  box-shadow: 0 2px 10px rgba(15, 118, 110, .14);
}
.chat-message[data-replyable="1"] .message-hint {
  display: block;
  font-size: 11px;
  color: #9aa3b2;
  margin-top: 4px;
}
.chat-message[data-replyable="1"]:hover .message-hint { color: var(--wp-primary); }

/* 输入框顶部提示当前正在私聊谁 */
.chat-reply-tip {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 12px;
  color: #b45309;
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  flex-shrink: 0;
}
.chat-reply-tip.show { display: flex; }
.chat-reply-tip .chat-reply-name { font-weight: 600; }
.chat-reply-tip .chat-reply-cancel {
  margin-left: auto;
  cursor: pointer;
  color: #b45309;
  text-decoration: underline;
  background: none;
  border: none;
  padding: 0;
  font-size: 12px;
}
