/*
  AI客服聊天组件 - 样式表
  
  右下角悬浮聊天窗口样式
  作者：卡卡 🐾
  日期：2026-02-12
*/

/* ===== CSS 变量 ===== */
:root {
    --chat-primary: #4F46E5;
    --chat-primary-dark: #4338CA;
    --chat-primary-light: #818CF8;
    --chat-bg: #FFFFFF;
    --chat-bg-secondary: #F9FAFB;
    --chat-text: #1F2937;
    --chat-text-secondary: #6B7280;
    --chat-border: #E5E7EB;
    --chat-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --chat-radius: 12px;
    --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== 重置样式 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===== 悬浮按钮 ===== */
.chat-toggle {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    z-index: 99999;
    color: white;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(79, 70, 229, 0.5);
}

.chat-toggle:active {
    transform: scale(0.95);
}

.chat-toggle .chat-icon {
    width: 28px;
    height: 28px;
}

.chat-toggle .close-icon {
    width: 24px;
    height: 24px;
}

/* ===== 聊天窗口 ===== */
.chat-window {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99999;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== 头部 ===== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-dark));
    color: white;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.chat-header-text {
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #10B981;
    border-radius: 50%;
}

.minimize-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    color: white;
}

.minimize-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.minimize-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== 消息区域 ===== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--chat-bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 消息项 */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.user-message .message-avatar {
    background: var(--chat-primary);
}

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.user-message .message-content {
    background: var(--chat-primary);
    color: white;
}

.message-content p {
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-time {
    display: block;
    font-size: 11px;
    color: var(--chat-text-secondary);
    margin-top: 4px;
    text-align: right;
}

.user-message .message-time {
    color: rgba(255, 255, 255, 0.7);
}

/* 加载动画 */
.message.loading .message-content {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--chat-text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ===== 输入区域 ===== */
.chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--chat-border);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--chat-bg-secondary);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    border: 1px solid var(--chat-border);
    transition: var(--chat-transition);
}

.input-wrapper:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 24px;
}

#chat-input::placeholder {
    color: var(--chat-text-secondary);
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--chat-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chat-transition);
    color: white;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

.send-btn:disabled {
    background: var(--chat-border);
    cursor: not-allowed;
    transform: none;
}

.send-btn svg {
    width: 20px;
    height: 20px;
    margin-left: 2px;
}

.input-hint {
    font-size: 11px;
    color: var(--chat-text-secondary);
    margin-top: 8px;
    text-align: center;
}

/* ===== 响应式设计 ===== */
@media (max-width: 480px) {
    .chat-window {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .chat-toggle {
        right: 16px;
        bottom: 16px;
        width: 48px;
        height: 48px;
    }
}

/* ===== 错误状态 ===== */
.message.error .message-content {
    background: #FEE2E2;
    color: #DC2626;
}

/* ===== Markdown 样式 ===== */
.message-text {
    line-height: 1.6;
}

.message-text p {
    margin: 0 0 8px 0;
}

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

.message-text b,
.message-text strong {
    font-weight: 600;
    color: var(--chat-primary);
}

.message-text i,
.message-text em {
    font-style: italic;
}

.message-text s,
.message-text strike {
    text-decoration: line-through;
    opacity: 0.7;
}

.message-text code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.9em;
}

.user-message .message-text code {
    background: rgba(255, 255, 255, 0.2);
}

.message-text a {
    color: var(--chat-primary);
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-text h3,
.message-text h4,
.message-text h5 {
    margin: 0 0 8px 0;
    font-weight: 600;
}

.message-text h3 { font-size: 1.1em; }
.message-text h4 { font-size: 1em; }
.message-text h5 { font-size: 0.95em; }

.message-text ul,
.message-text ol {
    margin: 0 0 8px 0;
    padding-left: 20px;
}

.message-text li {
    margin-bottom: 4px;
}

.message-text blockquote {
    margin: 0 0 8px 0;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.05);
    border-left: 3px solid var(--chat-primary);
    border-radius: 0 4px 4px 0;
}

.message-text hr {
    border: none;
    border-top: 1px solid var(--chat-border);
    margin: 12px 0;
}

