/**
 * 1688o 万能助手 - 悬浮聊天窗口样式
 * 白底简洁中文界面，支持 PC 和手机
 */

/* ── 变量 ────────────────────────────────────────── */
:root {
  --chat-primary: #ff6a00;
  --chat-primary-hover: #e55d00;
  --chat-bg: #ffffff;
  --chat-border: #e5e7eb;
  --chat-text: #1f2937;
  --chat-text-secondary: #6b7280;
  --chat-user-bg: #fff7ed;
  --chat-assistant-bg: #f9fafb;
  --chat-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
  --chat-radius: 12px;
}

/* ── 悬浮按钮 ────────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  border-radius: 28px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(255, 106, 0, 0.3);
  transition: all 0.2s ease;
}

.chat-fab:hover {
  background: var(--chat-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(255, 106, 0, 0.4);
}

.chat-fab-active {
  opacity: 0;
  pointer-events: none;
}

.chat-fab-label {
  white-space: nowrap;
}

/* ── 聊天面板 ────────────────────────────────────── */
.chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  width: 400px;
  height: 600px;
  max-height: calc(100vh - 48px);
  background: var(--chat-bg);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-hidden {
  display: none !important;
}

/* ── 头部 ────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-bg);
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--chat-text);
}

.chat-avatar {
  font-size: 20px;
}

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

.chat-btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--chat-text-secondary);
  transition: all 0.15s ease;
}

.chat-btn-icon:hover {
  background: #f3f4f6;
  color: var(--chat-text);
}

/* ── 消息区域 ────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

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

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

.chat-message-system {
  align-self: center;
  max-width: 90%;
}

.chat-message-content {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-message-user .chat-message-content {
  background: var(--chat-user-bg);
  color: var(--chat-text);
  border-bottom-right-radius: 4px;
}

.chat-message-assistant .chat-message-content {
  background: var(--chat-assistant-bg);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}

.chat-message-system .chat-message-content {
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  text-align: center;
  border-radius: 8px;
}

.chat-typing {
  color: var(--chat-text-secondary);
  font-style: italic;
}

/* ── 输入区域 ────────────────────────────────────── */
.chat-input-area {
  border-top: 1px solid var(--chat-border);
  padding: 12px;
  background: var(--chat-bg);
}

.chat-input-tools {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.chat-btn-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--chat-text-secondary);
  transition: all 0.15s ease;
}

.chat-btn-tool:hover {
  background: #f3f4f6;
  color: var(--chat-primary);
  border-color: var(--chat-primary);
}

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

.chat-input {
  flex: 1;
  min-height: 36px;
  max-height: 100px;
  padding: 8px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.15s ease;
}

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

.chat-btn-send,
.chat-btn-stop {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--chat-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

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

.chat-btn-stop {
  background: #ef4444;
}

.chat-btn-stop:hover {
  background: #dc2626;
}

.chat-file-preview {
  margin-top: 8px;
  padding: 6px 10px;
  background: #f3f4f6;
  border-radius: 6px;
  font-size: 12px;
  color: var(--chat-text-secondary);
}

/* ── 历史列表 ────────────────────────────────────── */
.chat-history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-history-item {
  padding: 10px 12px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chat-history-item:hover {
  background: #f9fafb;
  border-color: var(--chat-primary);
}

.chat-history-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--chat-text);
}

.chat-history-time {
  font-size: 12px;
  color: var(--chat-text-secondary);
  margin-top: 4px;
}

.chat-btn-back {
  margin-bottom: 12px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--chat-text-secondary);
}

.chat-btn-back:hover {
  background: #f3f4f6;
}

/* ── 滚动条 ────────────────────────────────────── */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

/* ── 手机端适配 ────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-fab {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 13px;
  }

  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}

/* CHAT_WIDGET_PC_LARGE_V1 */
@media (min-width: 769px) {
  #chat-widget-panel,
  .chat-widget-panel {
    width: min(560px, calc(100vw - 40px)) !important;
    height: min(780px, 78vh) !important;
    min-width: 480px;
    min-height: 560px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  #chat-messages,
  .chat-messages {
    font-size: 15px;
    line-height: 1.75;
  }
}

/* CHAT_MESSAGE_TEXT_ACTIONS_V1 */
.chat-message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 4px 2px;
}

.chat-message-action-btn {
  border: 1px solid #d8dee9;
  border-radius: 8px;
  background: #ffffff;
  color: #40516b;
  padding: 6px 11px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: all .18s ease;
}

.chat-message-action-btn:hover {
  border-color: #2868ed;
  color: #2868ed;
  background: #f3f7ff;
}

.chat-message-download-btn {
  color: #ffffff;
  border-color: #2868ed;
  background: #2868ed;
}

.chat-message-download-btn:hover {
  color: #ffffff;
  background: #1556d8;
}
