/* ChatGPT 风格对话页 */
.chat-page {
  display: flex;
  flex-direction: column;
  height: calc(87vh - 2rem);
  min-height: 320px;
  background: #f7f7f8;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
}

.chat-clear-link {
  color: #6e6e80;
  text-decoration: none;
  font-size: 0.9rem;
}

.chat-clear-link:hover {
  color: #202123;
}

.chat_container_parent {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chat_container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem;
  margin: 0 auto;
  width: 100%;
  max-width: 48rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #f7f7f8;
  border: none;
}

/* 单条消息行 */
.chat-message {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 1rem 0;
}

.chat-message-user {
  justify-content: flex-end;
}

.chat-message-user {
  position: relative;
}

.chat-message-user .chat-message-content {
  /* 让图片区不被蓝底包住：气泡背景交给 .chat-user-text */
  background: transparent;
  color: inherit;
  border-radius: 0;
  padding: 0;
  max-width: 85%;
  box-shadow: none;
}

.chat-message-user .chat-user-text {
  background: #2f7cf6;
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 0.75rem 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.chat-message-user .chat-user-text p:last-child {
  margin-bottom: 0;
}

/* 用户气泡内 Markdown 会生成 <mark>/<kbd> 等，Bootstrap 默认黄底/黑底在蓝气泡里很突兀，此处收敛为与气泡一致的浅色强调 */
.chat-message-user .chat-user-text mark,
.chat-message-user .chat-user-text .mark {
  padding: 0.1em 0.2em;
  background-color: rgba(255, 255, 255, 0.28);
  color: inherit;
}

.chat-message-user .chat-user-text kbd {
  padding: 0.12em 0.35em;
  font-size: 0.88em;
  color: #fff;
  background-color: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 0.25rem;
  box-shadow: none;
}

.chat-user-actions {
  display: none;
  position: absolute;
  right: 0.25rem;
  bottom: -1.6rem;
  gap: 0.25rem;
  z-index: 5;
}

.chat-message-user:hover .chat-user-actions {
  display: flex;
}

.chat-message-user.is-editing .chat-user-actions,
.chat-message-user.is-editing:hover .chat-user-actions {
  display: none !important;
}

.chat-user-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-user-action-btn:hover {
  color: #111827;
  background: #f3f4f6;
}

.chat-edit-box {
  width: 85%;
  max-width: 85%;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 0.75rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chat-edit-textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  resize: vertical;
  outline: none;
  font-size: 0.95rem;
}

.chat-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.chat-edit-cancel,
.chat-edit-send {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  cursor: pointer;
}

.chat-edit-send {
  background: #2f7cf6;
  color: #fff;
  border-color: #2f7cf6;
}

.chat-edit-send:hover {
  background: #2563eb;
}

.chat-message-user .chat-message-content p:last-child {
  margin-bottom: 0;
}

.chat-message-assistant {
  justify-content: flex-start;
}

.chat-message-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-avatar-assistant {
  background: linear-gradient(135deg, #5436da 0%, #8b5cf6 100%);
  color: #fff;
}

.chat-message-assistant .chat-message-content-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 85%;
}

.chat-message-assistant .chat-message-content {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 18px 18px 18px 4px;
  padding: 0.75rem 1rem 2.4rem 1rem;
  min-height: 2.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.chat-message-assistant .chat-message-content p:last-child {
  margin-bottom: 0;
}

/* 助手消息排版：接近 ChatGPT 的克制型 Markdown 风格 */
.chat-message-assistant .chat-message-content {
  font-size: 1rem;
  line-height: 1.7;
}

.chat-message-assistant .chat-message-content h1,
.chat-message-assistant .chat-message-content h2,
.chat-message-assistant .chat-message-content h3,
.chat-message-assistant .chat-message-content h4 {
  margin: 0.9em 0 0.45em;
  line-height: 1.35;
  font-weight: 700;
}

.chat-message-assistant .chat-message-content h1 { font-size: 1.5rem; }
.chat-message-assistant .chat-message-content h2 { font-size: 1.3rem; }
.chat-message-assistant .chat-message-content h3 { font-size: 1.15rem; }
.chat-message-assistant .chat-message-content h4 { font-size: 1.05rem; }

.chat-message-assistant .chat-message-content p,
.chat-message-assistant .chat-message-content ul,
.chat-message-assistant .chat-message-content ol,
.chat-message-assistant .chat-message-content blockquote {
  margin: 0.45em 0;
}

.chat-message-assistant .chat-message-content ul,
.chat-message-assistant .chat-message-content ol {
  padding-left: 1.25em;
}

.chat-message-assistant .chat-message-content li {
  margin: 0.2em 0;
}

.chat-message-assistant .chat-message-content hr {
  margin: 0.9em 0;
  border: 0;
  border-top: 1px solid #e5e7eb;
}

.chat-message-assistant .chat-message-content blockquote {
  padding: 0.35em 0.8em;
  border-left: 3px solid #d1d5db;
  color: #4b5563;
  background: #f9fafb;
  border-radius: 4px;
}

.chat-message-assistant .chat-message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6em 0;
}

.chat-message-assistant .chat-message-content th,
.chat-message-assistant .chat-message-content td {
  border: 1px solid #e5e7eb;
  padding: 0.4em 0.55em;
  text-align: left;
}

.chat-message-assistant .chat-message-content th {
  background: #f9fafb;
}

.chat-answer-loading {
  color: #8e8ea0;
  font-size: 0.9rem;
}

.chat-answer-loading .fa-spinner,
.chat-answer-loading i.fa-spin {
  display: inline-block;
  animation: chat-loading-spin 0.8s linear infinite;
}

@keyframes chat-loading-spin {
  to { transform: rotate(360deg); }
}

.chat-copy-btn {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  background: transparent;
  border: none;
  color: #8e8ea0;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.chat-copy-btn:hover {
  color: #202123;
  background: #f0f0f0;
}

.chat-copy-btn.is-copied {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.12);
}

.chat-copy-btn.is-copied:hover {
  color: #16a34a;
  background: rgba(22, 163, 74, 0.12);
}

/* 代码块复制按钮（左下角） */
.chat-code-block {
  position: relative;
}

.chat-code-block pre {
  padding-top: 2.4rem;
}

.chat-code-copy-btn {
  position: absolute;
  right: 0.5rem;
  top: 0.5rem;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid #e5e7eb;
  color: #6b7280;
  cursor: pointer;
  padding: 0.25rem 0.35rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.chat-code-copy-btn:hover {
  color: #111827;
  background: rgba(255, 255, 255, 0.95);
}

.chat-code-copy-btn.is-copied {
  color: #16a34a;
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(22, 163, 74, 0.12);
}

/* 输入区：底部固定风格 */
.chat-input-wrapper {
  flex-shrink: 0;
  padding: 1rem;
  background: #fff;
  border-top: 1px solid #e5e5e5;
}

.chat-input-form {
  max-width: 48rem;
  margin: 0 auto;
}

.chat-input-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-attach-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-attach-btn:hover {
  background: #f3f4f6;
  color: #111827;
}

.chat-attachments {
  max-width: 48rem;
  margin: 0.5rem auto 0;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chat-attachment-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.chat-attachment-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-attachment-remove {
  position: absolute;
  right: 4px;
  top: 4px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
  line-height: 20px;
  padding: 0;
}

.chat-user-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.chat-user-image {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 12px;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

/* 图片放大预览（灯箱） */
.chat-image-viewer {
  position: fixed;
  inset: 0;
  z-index: 20000;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chat-image-viewer-img {
  max-width: min(1100px, 95vw);
  max-height: 90vh;
  border-radius: 12px;
  background: #111;
}

.chat-image-viewer-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
}

.chat-input-inner:focus-within {
  border-color: #2f7cf6;
  box-shadow: 0 0 0 2px rgba(47, 124, 246, 0.2);
}

#quessionInputBox {
  flex: 1;
  min-height: 48px; /* 默认约两行高度 */
  max-height: 200px;
  padding: 0.5rem 0;
  border: none;
  outline: none;
  resize: none;
  font-size: 1rem;
  line-height: 1.5;
  background: transparent;
}

#quessionInputBox::placeholder {
  color: #8e8ea0;
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border: none;
  border-radius: 50%;
  background: #2f7cf6;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.chat-send-btn:disabled:hover {
  background: #cbd5e1;
}

.chat-send-btn:hover:not(.is-loading) {
  background: #2563eb;
}

.chat-send-btn.is-loading {
  background: #dc2626;
  cursor: pointer;
}

.chat-send-btn.is-loading:hover {
  background: #b91c1c;
}

.chat-send-btn i {
  animation: none;
}

.chat-answer-stopped {
  color: #8e8ea0;
  font-size: 0.9rem;
}

.chat-input-hint {
  margin: 0.5rem 0 0;
  font-size: 0.75rem;
  color: #8e8ea0;
  text-align: center;
}

.chat-alert {
  /* 覆盖 resource/css/public/common.css 里对 .alert 的全局 fixed 居中弹窗样式 */
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  top: auto;
  left: auto;
  transform: none;
  z-index: 10000;
  display: none;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* 代码块在对话中的样式 */
.chat-message-content pre,
.chat-message-content .code-block {
  margin: 0.5rem 0;
  padding: 0.75rem 1rem;
  background: #f3f4f6;
  color: #111827;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.9rem;
}

.chat-message-content code {
  font-family: ui-monospace, monospace;
}

.chat-message-content pre code {
  color: inherit;
  background: transparent;
}

.chat-message-content :not(pre) > code {
  background: #eef2ff;
  color: #111827;
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

/* 九宫格模态 */
.nine-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-gap: 10px;
}

.grid-item {
  background: #f0f4ff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  cursor: pointer;
  height: 100px;
  overflow-y: auto;
  padding: 10px;
}

.grid-item:hover {
  background: #e0e7ff;
}

.grid-item:active {
  background: #c7d2fe;
}

/* 选中后保持背景色不恢复 */
.grid-item.grid-item-selected {
  background: #c7d2fe;
}
