/**
 * LiveChat 嵌入式聊天组件样式
 * 响应式设计，兼容各种设备
 * 统一配色方案
 */

@import url('./variables.css');

/* 浮动按钮 */
.livechat-widget-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary-color);
    color: var(--text-white);
    padding: 14px 24px;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 9999;
    transition: all 0.3s ease;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
}

.livechat-widget-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.livechat-widget-button:active {
    transform: translateY(0);
}

.livechat-widget-button.flash {
    animation: flashButton 1s ease-in-out;
}

@keyframes flashButton {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* 按钮位置：左下角 */
.livechat-widget-button.bottom-left {
    right: auto;
    left: 20px;
}

/* 聊天窗口 */
.livechat-widget-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 40px);
    max-width: calc(100vw - 40px);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: none;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: top 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                right 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.livechat-widget-window.open {
    display: flex;
}

/* 全屏模式 */
.livechat-widget-window.maximized {
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    border-radius: 0;
    box-shadow: none;
}

/* 窗口头部 */
.livechat-widget-header {
    background: var(--primary-gradient);
    color: var(--text-white);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.livechat-widget-header-content {
    flex: 1;
}

.livechat-widget-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.livechat-widget-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.chat-status {
    font-size: 12px;
    opacity: 0.9;
}

.livechat-widget-maximize,
.livechat-widget-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
    flex-shrink: 0;
}

.livechat-widget-maximize:hover,
.livechat-widget-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background: var(--bg-tertiary);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Important for flex child to shrink properly */
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* 消息样式 */
.message {
    display: flex;
    margin-bottom: 12px;
}

.message.guest {
    justify-content: flex-end;
}

.message.staff {
    justify-content: flex-start;
}

.message.system {
    justify-content: center;
}

.message-content {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-width: 0;
    flex: 0 1 75%;
}

.message.guest .message-content {
    align-items: flex-end;
}

.message.staff .message-content {
    align-items: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.5;
    white-space: normal;
    display: inline-block;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow: hidden;
}

.message-bubble.guest {
    background: var(--primary-color);
    color: var(--text-white);
    border-bottom-right-radius: 4px;
}

.message-bubble.staff {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 4px;
    padding: 0 4px;
}

.system-message {
    font-size: 13px;
    color: #333;
    text-align: center;
    padding: 10px 12px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 8px;
    line-height: 1.6;
    font-weight: 500;
}

.system-message a {
    color: var(--primary-color);
    text-decoration: underline;
    font-weight: 500;
}

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

.waiting-message {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #999;
    font-size: 14px;
    padding: 20px;
}

.loading {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-medium);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 输入区域 */
.chat-input-area {
    display: flex;
    gap: 6px;
    padding: 12px;
    background: white;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    box-sizing: border-box;
    min-height: 70px;
    align-items: center;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
}

.chat-emoji-btn, .chat-image-btn {
    padding: 8px 10px;
    background: #f0f0f0;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.3s;
    flex-shrink: 0;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-emoji-btn:hover, .chat-image-btn:hover {
    background: var(--border-light);
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--border-medium);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    box-sizing: border-box;
}

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

.chat-input:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.chat-send {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.3s;
    flex-shrink: 0;
    white-space: nowrap;
    min-width: 60px;
}

.chat-send:hover:not(:disabled) {
    background: var(--primary-dark);
}

.chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 图片预览区域 */
.chat-image-preview {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-light);
}

.image-preview-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
}

.image-preview-container img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    display: block;
}

.image-preview-cancel {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.image-preview-cancel:hover {
    background: var(--error-dark);
}

.image-preview-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* 图片消息样式 */
.message-image {
    padding: 4px;
}

.message-image img {
    max-width: 300px;
    max-height: 400px;
    display: block;
    border-radius: 8px;
}

.message.staff .message-image img {
    max-width: 250px;
}

/* 响应式设计 - 移动设备 */
@media (max-width: 480px) {
    .livechat-widget-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        min-width: 0 !important;
        border-radius: 0 !important;
        transform-origin: center center;
        box-sizing: border-box !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .livechat-widget-window:not(.maximized) {
        /* On mobile, always fullscreen when open */
    }
    
    .livechat-widget-window * {
        box-sizing: border-box;
    }
    
    .livechat-widget-button {
        bottom: 15px;
        right: 15px;
        padding: 12px 20px;
        font-size: 14px;
    }
    
    .livechat-widget-button.bottom-left {
        left: 15px;
    }
    
    /* Hide maximize button on mobile (always fullscreen) */
    .livechat-widget-maximize {
        display: none;
    }
    
    /* 移动端消息区域优化 */
    .chat-messages {
        width: 100% !important;
        max-width: 100% !important;
        padding: 15px !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }
    
    .message {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .message-content {
        max-width: 85% !important;
        width: auto !important;
        box-sizing: border-box !important;
        flex: 0 1 85% !important;
    }
    
    .message-bubble {
        max-width: 100% !important;
        width: auto !important;
        box-sizing: border-box !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        word-break: break-word !important;
        white-space: normal !important;
        overflow: hidden !important;
        display: inline-block !important;
    }
    
    /* 移动端输入区域优化 */
    .chat-input-area {
        padding: 10px !important;
        gap: 4px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .chat-emoji-btn, .chat-image-btn {
        min-width: 32px;
        height: 32px;
        padding: 6px 8px;
        flex-shrink: 0;
    }
    
    .chat-input {
        min-width: 0 !important;
        max-width: 100% !important;
        width: auto !important;
        flex: 1 1 auto !important;
        box-sizing: border-box !important;
    }
    
    .chat-send {
        padding: 8px 12px;
        min-width: 50px;
        font-size: 13px;
        flex-shrink: 0;
    }
    
    /* 确保头部不会超出 */
    .livechat-widget-header {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

/* 平板设备 */
@media (min-width: 481px) and (max-width: 768px) {
    .livechat-widget-window {
        width: 360px;
        height: 560px;
    }
    
    /* 平板端输入区域优化 */
    .chat-input-area {
        padding: 10px;
        gap: 5px;
    }
    
    .chat-emoji-btn, .chat-image-btn {
        min-width: 34px;
        height: 34px;
        padding: 7px 9px;
    }
    
    .chat-send {
        padding: 8px 14px;
        min-width: 55px;
    }
}

/* 确保按钮在小屏幕上不会被遮挡 */
@media (max-width: 768px) {
    .livechat-widget-button {
        bottom: 80px; /* 为移动浏览器底部导航栏留出空间 */
    }
    
    /* 小屏幕输入区域优化 */
    .chat-input-area {
        padding: 10px;
        gap: 5px;
    }
    
    .chat-emoji-btn, .chat-image-btn {
        min-width: 34px;
        height: 34px;
        padding: 7px 9px;
    }
    
    .chat-send {
        padding: 8px 14px;
        min-width: 55px;
    }
}

/* Emoji Picker Styles for Widget */
.livechat-widget-window .chat-input-area {
    position: relative;
}

/* Make emojis larger in chat messages */
.livechat-widget-window .message-bubble {
    font-size: 15px;
    line-height: 1.6;
}

.livechat-widget-window .emoji-in-message {
    font-size: 20px;
    vertical-align: middle;
    display: inline;
    margin: 0 2px;
    line-height: 1;
}

.livechat-widget-window .emoji-picker {
    position: absolute;
    bottom: 70px;
    left: 16px;
    width: 260px;
    max-height: 220px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.livechat-widget-window .emoji-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #e0e0e0;
    background: var(--bg-tertiary);
    font-size: 13px;
    font-weight: 600;
    color: #333;
}

.livechat-widget-window .emoji-picker-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.2s;
}

.livechat-widget-window .emoji-picker-close:hover {
    color: #333;
}

.livechat-widget-window .emoji-picker-content {
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 180px;
    justify-content: flex-start;
    align-content: flex-start;
}

.livechat-widget-window .emoji-item {
    background: none;
    border: none;
    font-size: 20px;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.livechat-widget-window .emoji-item:hover {
    background: #f0f0f0;
    transform: scale(1.15);
}

.livechat-widget-window .emoji-item:active {
    transform: scale(1.05);
}

/* Browser compatibility improvements */
@supports not (display: flex) {
    .livechat-widget-window {
        display: block;
    }
    
    .livechat-widget-header {
        display: table;
        width: 100%;
    }
    
    .chat-messages {
        display: block;
        height: auto;
    }
}

/* Smooth scrolling for older browsers */
.chat-messages {
    -webkit-overflow-scrolling: touch; /* iOS smooth scroll */
}

/* Fix for iOS Safari viewport height issue */
@supports (-webkit-touch-callout: none) {
    .livechat-widget-window {
        max-height: -webkit-fill-available;
    }
    
    @media (max-width: 480px) {
        .livechat-widget-window {
            max-height: -webkit-fill-available !important;
            width: 100vw !important;
            max-width: 100vw !important;
            left: 0 !important;
            right: 0 !important;
        }
    }
}

/* 防止移动端页面横向滚动 */
@media (max-width: 480px) {
    body.livechat-widget-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    html.livechat-widget-open {
        overflow: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
}

