/**
 * 享聊通信智能客服系统 - 样式文件
 * 版本: 2.1.2
 * 更新日期: 2024-10-26
 * 修复: 思考冒泡大小优化、关闭按钮、输入框双重边框
 */

/* ==================== 全局变量 ==================== */
:root {
    --primary-color: #667eea;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-light: rgba(102, 126, 234, 0.1);
    --secondary-color: #764ba2;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --text-color: #1f2937;
    --text-light: #6b7280;
    --text-lighter: #9ca3af;
    --border-color: #e5e7eb;
    --bg-light: #f9fafb;
    --bg-lighter: #f3f4f6;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== 1. 浮动按钮 ==================== */
.enjoytalk-float-btn {
    position: fixed;
    width: 64px;
    height: 64px;
    background: var(--primary-gradient);
    border-radius: var(--radius-full);
    cursor: pointer;
    box-shadow: var(--shadow-2xl);
    z-index: 999998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-slow);
    border: none;
    outline: none;
}

.enjoytalk-float-btn.bottom-right {
    bottom: 30px;
    right: 30px;
}

.enjoytalk-float-btn.bottom-left {
    bottom: 30px;
    left: 30px;
}

.enjoytalk-float-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 25px 40px rgba(102, 126, 234, 0.5);
}

.enjoytalk-float-btn:active {
    transform: scale(1.05);
}

.enjoytalk-float-btn svg {
    width: 30px;
    height: 30px;
    color: var(--white);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* 脉冲动画 */
.enjoytalk-float-btn .pulse-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
    border: 3px solid var(--primary-color);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0;
        transform: scale(1.4);
    }
}

/* ==================== 2. 聊天窗口容器 ==================== */
.enjoytalk-chat-window {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 420px;
    height: 650px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    z-index: 999999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 
                 'Hiragino Sans GB', 'Microsoft YaHei', 'Roboto', 'Helvetica Neue', sans-serif;
    transition: all var(--transition-slow);
    opacity: 1;
    transform: translateY(0) scale(1);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.enjoytalk-chat-window.hidden {
    display: none;
    opacity: 0;
    transform: translateY(30px) scale(0.95);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .enjoytalk-chat-window {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
        max-height: -webkit-fill-available;
    }
    
    .enjoytalk-float-btn {
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
    }
    
    .enjoytalk-float-btn svg {
        width: 28px;
        height: 28px;
    }
}

/* ==================== 3. 聊天窗口头部 ==================== */
.chat-header {
    background: var(--primary-gradient);
    color: var(--white);
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.chat-header .header-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chat-header .avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.chat-header .title h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.chat-header .status {
    margin: 6px 0 0 0;
    font-size: 13px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 500;
}

.chat-header .status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.5;
        transform: scale(0.9);
    }
}

/* 🔥 修复：关闭按钮样式优化 */
.chat-header .close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: var(--white);
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    padding: 0;
    backdrop-filter: blur(5px);
    flex-shrink: 0;
}

.chat-header .close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

.chat-header .close-btn:active {
    transform: rotate(90deg) scale(0.95);
}

.chat-header .close-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
}

/* ==================== 4. 聊天窗口主体 ==================== */
.chat-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
}

/* ==================== 5. 注册表单 ==================== */
.register-form {
    padding: 32px 28px;
    overflow-y: auto;
}

.register-form.hidden {
    display: none;
}

.register-form h3 {
    margin: 0 0 10px 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-color);
    letter-spacing: -0.5px;
}

.register-form p {
    margin: 0 0 28px 0;
    font-size: 15px;
    color: var(--text-light);
    line-height: 1.6;
}

.register-form form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.register-form input,
.register-form select {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    transition: all var(--transition-base);
    background: var(--white);
    box-sizing: border-box;
    color: var(--text-color);
    font-weight: 500;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* 🔥 下拉框自定义样式 */
.register-form select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 20px;
    padding-right: 48px;
    cursor: pointer;
}

.register-form select option {
    padding: 12px;
    font-size: 15px;
    color: var(--text-color);
    background: var(--white);
}

.register-form select option:first-child {
    color: var(--text-lighter);
}

.register-form select:hover {
    border-color: var(--primary-color);
    background-color: var(--bg-lighter);
}

.register-form input:hover,
.register-form select:hover {
    border-color: var(--primary-color);
    background-color: var(--bg-lighter);
}

/* 🔥 修复：聚焦时统一视觉效果，去除双重边框 */
.register-form input:focus,
.register-form select:focus {
    outline: none;
    border-color: transparent;
    background-color: var(--white);
    box-shadow: 0 0 0 3px var(--primary-light), 
                0 0 0 1px var(--primary-color),
                0 2px 8px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
}

.register-form input::placeholder {
    color: var(--text-lighter);
    font-weight: 400;
}

/* 🔥 移动端禁止自动缩放 */
@media (max-width: 768px) {
    .register-form input,
    .register-form select {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation;
    }
    
    .register-form select {
        min-height: 50px;
        padding: 14px 48px 14px 18px;
    }
    
    .register-form select option {
        font-size: 16px;
    }
}

.register-form .submit-btn {
    width: 100%;
    padding: 16px;
    background: var(--primary-gradient);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-top: 12px;
    box-shadow: var(--shadow-md);
    letter-spacing: 0.5px;
}

.register-form .submit-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 24px rgba(102, 126, 234, 0.4);
}

.register-form .submit-btn:active {
    transform: translateY(-1px);
}

.register-form .submit-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: var(--shadow-sm);
}

/* ==================== 6. 聊天区域 ==================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-area.hidden {
    display: none;
}

/* ==================== 7. 消息列表 ==================== */
.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.messages::-webkit-scrollbar {
    width: 8px;
}

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

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

.messages::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ==================== 8. 消息气泡 ==================== */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

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

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

.message-content {
    padding: 14px 18px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.7;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-weight: 500;
}

.message.user .message-content {
    background: var(--primary-gradient);
    color: var(--white);
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.message.assistant .message-content {
    background: var(--white);
    color: var(--text-color);
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.message.system .message-content {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    text-align: center;
    font-size: 14px;
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.message-time {
    font-size: 12px;
    color: var(--text-lighter);
    margin-top: 6px;
    padding: 0 6px;
    font-weight: 500;
}

.message.user .message-time {
    text-align: right;
}

/* 🔥 修复：思考冒泡样式 - 更小更精致 */
#typing-indicator {
    display: flex;
    flex-direction: column;
    align-self: flex-start;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

#typing-indicator .message-content {
    background: var(--white);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    min-width: auto;
}

.typing-animation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 !important;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: #999;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* 旧的加载动画样式（保留兼容） */
.message.loading .message-content {
    display: flex;
    gap: 8px;
    padding: 18px 24px;
    background: var(--white);
    border: 1px solid var(--border-color);
}

.message.loading .dot {
    width: 9px;
    height: 9px;
    border-radius: var(--radius-full);
    background: var(--primary-color);
    animation: bounce 1.4s infinite ease-in-out;
}

.message.loading .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.message.loading .dot:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* ==================== 9. 转接信息 ==================== */
.transfer-info {
    text-align: center;
    padding: 24px;
}

.transfer-info p {
    margin: 0 0 14px 0;
    font-size: 15px;
    line-height: 1.7;
    font-weight: 500;
}

.transfer-info strong {
    font-size: 18px;
    color: var(--primary-color);
    font-weight: 700;
}

.transfer-info .qr-code {
    width: 220px;
    height: 220px;
    margin: 20px auto;
    display: block;
    border: 3px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.transfer-info .wechat-link {
    display: inline-block;
    padding: 12px 28px;
    background: var(--success-color);
    color: var(--white);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 15px;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
}

.transfer-info .wechat-link:hover {
    background: #059669;
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
}

.transfer-info .wechat-link:active {
    transform: translateY(-1px);
}

/* ==================== 10. 结束对话按钮 ==================== */
.end-btn {
    margin: 16px 24px;
    padding: 12px;
    background: transparent;
    color: var(--danger-color);
    border: 2px solid var(--danger-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition-base);
    font-weight: 600;
}

.end-btn:hover {
    background: var(--danger-color);
    color: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(239, 68, 68, 0.3);
}

.end-btn:active {
    transform: translateY(0);
}

/* ==================== 11. 输入区域 ==================== */
.input-area {
    padding: 20px 24px;
    background: var(--white);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 14px;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
}

.input-area input {
    flex: 1;
    padding: 14px 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: all var(--transition-base);
    background: var(--bg-light);
    color: var(--text-color);
    font-weight: 500;
}

/* 🔥 移动端输入框优化 */
@media (max-width: 768px) {
    .input-area input {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation;
    }
}

.input-area input:hover {
    border-color: var(--primary-color);
    background: var(--white);
}

/* 🔥 修复：聚焦时统一视觉效果，去除双重边框 */
.input-area input:focus {
    border-color: transparent;
    background: var(--white);
    box-shadow: 0 0 0 3px var(--primary-light), 
                0 0 0 1px var(--primary-color),
                0 2px 8px rgba(102, 126, 234, 0.15);
}

.input-area input::placeholder {
    color: var(--text-lighter);
    font-weight: 400;
}

.input-area input:disabled {
    background: var(--bg-lighter);
    cursor: not-allowed;
    opacity: 0.6;
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--primary-gradient);
    border: none;
    border-radius: var(--radius-full);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.5);
}

.send-btn:active:not(:disabled) {
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: var(--shadow-sm);
}

.send-btn svg {
    width: 22px;
    height: 22px;
}

/* ==================== 12. 工具类 ==================== */
.hidden {
    display: none !important;
}

/* ==================== 13. 无障碍支持 ==================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ==================== 14. 打印样式 ==================== */
@media print {
    .enjoytalk-float-btn,
    .enjoytalk-chat-window {
        display: none !important;
    }
}

/* ==================== 15. 动画优化 ==================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== 16. 高对比度模式支持 ==================== */
@media (prefers-contrast: high) {
    .register-form input,
    .register-form select,
    .input-area input {
        border-width: 3px;
    }
}

/* ==================== 17. 深色模式支持（可选） ==================== */
@media (prefers-color-scheme: dark) {
    /* 可根据需要添加深色模式样式 */
}

/* ==================== 18. 触摸优化 ==================== */
@media (hover: none) and (pointer: coarse) {
    .enjoytalk-float-btn,
    .chat-header .close-btn,
    .send-btn,
    .register-form .submit-btn,
    .end-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ==================== 19. 焦点可见性增强 ==================== */
:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}
