/**
 * WordPress AI智能客服助手 - 聊天窗口样式
 * 
 * @package WP_AI_Assistant
 * @since 1.0.0
 */

/* ========================================
   聊天窗口容器
   ======================================== */

#wpai-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 位置配置 */
#wpai-chat-widget.wpai-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

#wpai-chat-widget.wpai-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

#wpai-chat-widget.wpai-position-top-right {
    top: 20px;
    right: 20px;
}

#wpai-chat-widget.wpai-position-top-left {
    top: 20px;
    left: 20px;
}

/* ========================================
   聊天按钮（收起状态）
   ======================================== */

.wpai-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #007bff;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.wpai-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.5);
}

.wpai-chat-button .wpai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

/* 未读消息标记 */
.wpai-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #dc3545;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* ========================================
   聊天窗口（展开状态）
   ======================================== */

.wpai-chat-window {
    width: 380px;
    height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   窗口头部
   ======================================== */

.wpai-chat-header {
    background-color: #007bff;
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.wpai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wpai-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.wpai-header-text {
    display: flex;
    flex-direction: column;
}

.wpai-header-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

.wpai-header-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.wpai-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background-color: #28a745;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.wpai-close-button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.wpai-close-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.wpai-close-button svg {
    width: 24px;
    height: 24px;
}

/* ========================================
   消息列表区域
   ======================================== */

.wpai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 自定义滚动条 */
.wpai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.wpai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.wpai-chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 3px;
}

.wpai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* ========================================
   消息样式
   ======================================== */

.wpai-message {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 用户消息 */
.wpai-message-user {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.wpai-message-user .wpai-message-content {
    align-items: flex-end;
}

.wpai-message-user .wpai-message-bubble {
    background-color: #007bff;
    color: white;
    border-radius: 18px 18px 4px 18px;
}

/* AI消息 */
.wpai-message-assistant {
    flex-direction: row;
}

.wpai-message-assistant .wpai-message-content {
    align-items: flex-start;
}

.wpai-message-assistant .wpai-message-bubble {
    background-color: white;
    color: #2d3748;
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* 消息头像 */
.wpai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* 消息内容 */
.wpai-message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 75%;
}

.wpai-message-bubble {
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
}

.wpai-message-time {
    font-size: 11px;
    color: #718096;
    padding: 0 4px;
}

/* 错误消息 */
.wpai-message-error {
    background-color: #fff5f5 !important;
    color: #c53030 !important;
    border: 1px solid #feb2b2;
    display: flex;
    align-items: center;
    gap: 8px;
}

.wpai-message-error svg {
    flex-shrink: 0;
}

/* ========================================
   加载指示器
   ======================================== */

.wpai-loading-indicator .wpai-message-bubble {
    display: flex;
    align-items: center;
    gap: 12px;
}

.wpai-typing-indicator {
    display: flex;
    gap: 4px;
}

.wpai-typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #cbd5e0;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.wpai-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.wpai-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.wpai-thinking-text {
    font-size: 13px;
    color: #718096;
}

/* ========================================
   输入区域
   ======================================== */

.wpai-chat-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.wpai-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.wpai-chat-input {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 40px;
    max-height: 120px;
    overflow-y: hidden;
}

.wpai-chat-input:focus {
    border-color: #007bff;
}

.wpai-chat-input::placeholder {
    color: #a0aec0;
}

.wpai-send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #007bff;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.wpai-send-button:hover {
    background-color: #0056b3;
    transform: scale(1.05);
}

.wpai-send-button:active {
    transform: scale(0.95);
}

.wpai-send-button:disabled {
    background-color: #cbd5e0;
    cursor: not-allowed;
    transform: none;
}

.wpai-send-button svg {
    width: 20px;
    height: 20px;
}

/* ========================================
   响应式设计
   ======================================== */

@media (max-width: 768px) {
    #wpai-chat-widget {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
        top: auto !important;
    }
    
    .wpai-chat-window {
        width: 100%;
        height: calc(100vh - 20px);
        max-height: 600px;
        border-radius: 16px 16px 0 0;
    }
    
    .wpai-message-content {
        max-width: 80%;
    }
}

@media (max-width: 480px) {
    .wpai-chat-button {
        width: 56px;
        height: 56px;
    }
    
    .wpai-chat-button .wpai-avatar {
        width: 36px;
        height: 36px;
    }
    
    .wpai-chat-window {
        max-height: calc(100vh - 20px);
    }
    
    .wpai-chat-header {
        padding: 12px 16px;
    }
    
    .wpai-header-avatar {
        width: 36px;
        height: 36px;
    }
    
    .wpai-header-title {
        font-size: 15px;
    }
    
    .wpai-chat-messages {
        padding: 16px;
    }
    
    .wpai-chat-input-area {
        padding: 12px 16px;
    }
}

/* ========================================
   深色模式支持
   ======================================== */

@media (prefers-color-scheme: dark) {
    .wpai-chat-window {
        background: #1a202c;
    }
    
    .wpai-chat-messages {
        background-color: #2d3748;
    }
    
    .wpai-message-assistant .wpai-message-bubble {
        background-color: #4a5568;
        color: #e2e8f0;
    }
    
    .wpai-message-time {
        color: #a0aec0;
    }
    
    .wpai-chat-input-area {
        background: #1a202c;
        border-top-color: #4a5568;
    }
    
    .wpai-chat-input {
        background: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .wpai-chat-input::placeholder {
        color: #718096;
    }
}

/* ========================================
   打印样式
   ======================================== */

@media print {
    #wpai-chat-widget {
        display: none !important;
    }
}

/* ========================================
   辅助功能
   ======================================== */

.wpai-chat-button:focus,
.wpai-close-button:focus,
.wpai-send-button:focus,
.wpai-chat-input:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* 减少动画（用户偏好） */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
