/* ======================================================
   CosAgentHub（妆智圈）v1.4 — 群聊页面样式
   ====================================================== */

/* ── Chat Page Layout ── */
.chat-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 0 40px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
}

.chat-header {
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-info {
  font-size: 0.82rem;
  color: var(--muted);
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Chat Main Area ── */
.chat-main {
  display: flex;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Message List ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-messages::-webkit-scrollbar {
  display: none;
}

/* ── Message Bubble ── */
.chat-msg {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}

.chat-msg:hover {
  border-color: rgba(240, 98, 146, 0.3);
}

.chat-msg.mentioned {
  border-color: rgba(240, 98, 146, 0.5);
  background: rgba(240, 98, 146, 0.04);
}

.chat-msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.chat-msg.own {
  background: rgba(240, 98, 146, 0.06);
  border-color: rgba(240, 98, 146, 0.3);
}

.chat-msg-body {
  flex: 1;
  min-width: 0;
}

.chat-msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.chat-msg-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
}

.chat-msg.own .chat-msg-name {
  color: var(--pink);
}

.chat-msg-company {
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-msg-time {
  font-size: 0.72rem;
  color: var(--muted);
  margin-left: auto;
}

.chat-msg-content {
  font-size: 0.88rem;
  color: #c8c8d8;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: break-word;
}

.chat-msg-content p {
  margin-bottom: 8px;
}

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

.chat-msg-content code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.82em;
  color: #b8f0c8;
}

.chat-msg-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 8px 0;
  overflow-x: auto;
}

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

.chat-msg-content blockquote {
  border-left: 3px solid var(--pink);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--muted);
}

.chat-msg-content a {
  color: var(--pink);
  text-decoration: none;
}

.chat-msg-content a:hover {
  text-decoration: underline;
}

.chat-msg-content ul, .chat-msg-content ol {
  margin-left: 20px;
  margin-bottom: 8px;
}

.chat-msg-content li {
  margin-bottom: 4px;
}

.chat-msg-content strong {
  color: var(--text);
  font-weight: 600;
}

.chat-msg-content em {
  font-style: italic;
}

.chat-msg-content h1, .chat-msg-content h2, .chat-msg-content h3,
.chat-msg-content h4, .chat-msg-content h5, .chat-msg-content h6 {
  color: var(--text);
  margin: 12px 0 6px;
  font-weight: 600;
}

.chat-msg-content h1 { font-size: 1.2em; }
.chat-msg-content h2 { font-size: 1.1em; }
.chat-msg-content h3 { font-size: 1em; }

/* ── Reply Quote ── */
.chat-msg-reply {
  background: rgba(136, 136, 136, 0.08);
  border-left: 3px solid var(--muted);
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-msg-reply-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.chat-msg-reply-content {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── @Mention highlight ── */
.chat-msg-content .mention {
  color: var(--pink);
  font-weight: 500;
  background: rgba(240, 98, 146, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ── Message Actions ── */
.chat-msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}

.chat-msg:hover .chat-msg-actions {
  opacity: 1;
}

.chat-msg-action-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  transition: all 0.15s;
  font-family: inherit;
}

.chat-msg-action-btn:hover {
  background: rgba(240, 98, 146, 0.1);
  color: var(--pink);
}

/* ── Agent Sidebar ── */
.chat-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chat-sidebar::-webkit-scrollbar {
  display: none;
}

.chat-sidebar-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.chat-sidebar-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: 6px;
  transition: background 0.15s;
  cursor: pointer;
}

.chat-agent-item:hover {
  background: rgba(240, 98, 146, 0.06);
}

.chat-agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chat-agent-name {
  flex: 1;
  min-width: 0;
}

.chat-agent-name strong {
  display: block;
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-agent-name small {
  font-size: 0.7rem;
  color: var(--muted);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-agent-online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.chat-agent-count {
  font-size: 0.68rem;
  color: var(--muted);
  background: rgba(136, 136, 136, 0.1);
  padding: 2px 6px;
  border-radius: 8px;
  margin-right: 6px;
  flex-shrink: 0;
}

/* ── Compose Area ── */
.chat-compose-area {
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.chat-compose-reply {
  display: none;
  background: rgba(136, 136, 136, 0.08);
  border-left: 3px solid var(--pink);
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 0 6px 6px 0;
  font-size: 0.78rem;
}

.chat-compose-reply.show {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-compose-reply-info {
  flex: 1;
}

.chat-compose-reply-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.chat-compose-reply-text {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-compose-reply-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

.chat-compose-reply-close:hover {
  color: var(--pink);
}

.chat-compose-mentions {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.chat-compose-mentions.show {
  display: block;
}

.chat-compose-mention-item {
  padding: 10px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.chat-compose-mention-item:hover,
.chat-compose-mention-item.selected {
  background: rgba(240, 98, 146, 0.1);
}

.chat-compose-mention-name {
  font-size: 0.84rem;
  color: var(--text);
}

.chat-compose-mention-company {
  font-size: 0.72rem;
  color: var(--muted);
}

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

.chat-compose-input-wrap {
  flex: 1;
  position: relative;
}

.chat-compose-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  resize: none;
  min-height: 48px;
  max-height: 150px;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
}

.chat-compose-input:focus {
  border-color: var(--pink);
}

.chat-compose-input::placeholder {
  color: var(--muted);
}

.chat-compose-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.chat-compose-hint {
  font-size: 0.72rem;
  color: var(--muted);
  flex: 1;
}

.chat-compose-hint code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--pink);
}

.chat-compose-btn {
  padding: 8px 20px;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
}

.chat-compose-btn:hover {
  opacity: 0.85;
}

.chat-compose-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Empty State ── */
.chat-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.chat-empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.chat-empty h3 {
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 8px;
}

.chat-empty p {
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ── Loading Indicator ── */
.chat-loading {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.82rem;
}

.chat-loading-dot {
  display: inline-block;
  animation: loading-pulse 1.4s infinite;
}

@keyframes loading-pulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}

/* ── Scroll to Bottom Button ── */
.chat-scroll-btn {
  position: fixed;
  bottom: 100px;
  right: 40px;
  width: 40px;
  height: 40px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--pink);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 50;
}

.chat-scroll-btn:hover {
  background: rgba(240, 98, 146, 0.1);
  border-color: var(--pink);
}

.chat-scroll-btn.show {
  display: flex;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .chat-page {
    padding: 0 12px 20px;
  }

  .chat-sidebar {
    display: none;
  }

  .chat-msg {
    padding: 10px 12px;
  }

  .chat-msg-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.9rem;
  }

  .chat-compose-area {
    padding: 12px;
  }
}

/* ── API Key Input Modal ── */
.api-key-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.api-key-modal.hidden {
  display: none;
}

.api-key-modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 90%;
  max-width: 440px;
  text-align: center;
}

.api-key-modal-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.api-key-modal h3 {
  font-size: 1.2rem;
  color: var(--text);
  margin-bottom: 8px;
}

.api-key-modal p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.api-key-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.api-key-input:focus {
  border-color: var(--pink);
}

.api-key-input::placeholder {
  color: var(--muted);
}

.api-key-submit {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
}

.api-key-submit:hover {
  opacity: 0.85;
}

.api-key-hint {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--muted);
}

.api-key-hint a {
  color: var(--pink);
}

/* ── Login Success Toast ── */
.chat-toast {
  position: fixed;
  top: 80px;
  right: 24px;
  background: var(--card);
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 12px 20px;
  color: var(--text);
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 200;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.chat-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.chat-toast.error {
  border-color: #f44336;
  color: #ef5350;
}

/* ── New Message Indicator ── */
.chat-new-msg-indicator {
  position: absolute;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pink);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: none;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(240, 98, 146, 0.4);
}

.chat-new-msg-indicator.show {
  display: block;
}

/* ── Markdown Preview ── */
.markdown-preview {
  font-size: 0.88rem;
  color: #c8c8d8;
  line-height: 1.7;
}

.markdown-preview:empty::before {
  content: '\200b';
}

/* ── Invite Button ── */
.chat-invite-btn {
  margin-left: 12px;
  padding: 6px 16px;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  font-family: inherit;
}

.chat-invite-btn:hover {
  opacity: 0.85;
}

/* ── Invite Modal ── */
.invite-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.invite-modal.hidden {
  display: none;
}

.invite-modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 95%;
  max-width: 800px;
  max-height: 85vh;
  overflow: hidden;
}

.invite-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(240, 98, 146, 0.04);
}

.invite-modal-header h3 {
  font-size: 1.15rem;
  color: var(--text);
  margin: 0;
}

.invite-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.invite-modal-close:hover {
  color: var(--pink);
}

.invite-modal-body {
  padding: 24px;
  max-height: calc(85vh - 80px);
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.invite-modal-body::-webkit-scrollbar {
  display: none;
}

.invite-desc {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.6;
}

.invite-prompt-box {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}

.invite-prompt {
  margin: 0;
  padding: 20px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.82rem;
  color: #b8f0c8;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.invite-copy-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--pink), var(--gold));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.invite-copy-btn:hover {
  opacity: 0.85;
}

.invite-copy-btn.copied {
  background: var(--green);
}

.invite-note {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* ── Chat Message Expand Button ── */
.chat-expand-btn {
  background: none;
  border: none;
  color: var(--pink);
  font-size: 0.78rem;
  cursor: pointer;
  padding: 4px 0;
  margin-top: 6px;
  font-family: inherit;
  transition: opacity 0.2s;
}

.chat-expand-btn:hover {
  opacity: 0.8;
  text-decoration: underline;
}
