/* 客服對話窗口樣式 */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Segoe UI', 'Microsoft JhengHei', Arial, sans-serif;
}

.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #5374f8 0%, #232369 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(83, 116, 248, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(83, 116, 248, 0.4);
}

.chat-toggle i {
    color: white;
    font-size: 24px;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
}

.chat-window {
    display: none;
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 350px;
    height: 650px; /* 增加高度从500px到650px，让客户看得更清楚 */
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden !important;
    flex-direction: column !important;
}

.chat-window.open {
    display: flex !important;
    flex-direction: column !important;
}

.chat-header {
    background: linear-gradient(135deg, #5374f8 0%, #232369 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info {
    display: flex;
    align-items: center;
}

.chat-header-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
}

.chat-header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header-text p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 20px;
    padding: 5px;
}

.chat-messages {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    padding: 15px;
    background: #f8f9fa;
    min-height: 0 !important; /* 重要：確保可以滾動而不會推擠其他元素 */
    max-height: calc(100% - 120px) !important; /* 預留輸入區域空間 */
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-end;
}

.chat-message.user {
    justify-content: flex-end;
}

.chat-message.admin {
    justify-content: flex-start;
}

.chat-message-content {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
}

.chat-message.user .chat-message-content {
    background: linear-gradient(135deg, #5374f8 0%, #232369 100%);
    color: white;
    border-bottom-right-radius: 5px;
}

.chat-message.admin .chat-message-content {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 5px;
}

.chat-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
    text-align: center;
}

.chat-input-area {
    flex-shrink: 0 !important; /* 防止輸入區域被壓縮 */
    flex-grow: 0 !important;
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
    position: relative !important;
    bottom: 0 !important;
    width: 100% !important;
    min-height: 60px !important; /* 確保最小高度 */
}

.chat-input-group {
    display: flex;
    align-items: center;
    background: #f5f5f5;
    border-radius: 25px;
    padding: 5px;
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 15px;
    background: transparent;
    font-size: 14px;
    resize: none;
    max-height: 80px;
}

.chat-send-btn {
    background: linear-gradient(135deg, #5374f8 0%, #232369 100%);
    border: none;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
    transition: all 0.2s ease;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.typing-indicator {
    display: none;
    padding: 10px 15px;
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.typing-indicator.show {
    display: block;
}

.chat-status {
    padding: 8px 15px;
    background: #e8f5e8;
    color: #2d5a2d;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid #e0e0e0;
}

.chat-status.offline {
    background: #fff3cd;
    color: #856404;
}

/* 管理員專用樣式 */
.admin-chat-window {
    width: 400px;
    height: 650px; /* 增加高度以保持与客户端一致 */
    bottom: 20px;
    right: 20px;
}

.admin-chat-tabs {
    display: flex;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.admin-chat-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border: none;
    background: transparent;
    font-size: 12px;
    color: #666;
    position: relative;
}

.admin-chat-tab.active {
    background: white;
    color: #5374f8;
    font-weight: 600;
}

.admin-chat-tab .unread-count {
    position: absolute;
    top: 5px;
    right: 10px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.admin-user-list {
    max-height: 200px;
    overflow-y: auto;
    border-bottom: 1px solid #e0e0e0;
}

.admin-user-item {
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s ease;
}

.admin-user-item:hover {
    background: #f8f9fa;
}

.admin-user-item.active {
    background: #e3f2fd;
    border-left: 3px solid #5374f8;
}

.admin-user-info h5 {
    margin: 0;
    font-size: 14px;
    color: #333;
}

.admin-user-info p {
    margin: 2px 0 0 0;
    font-size: 12px;
    color: #666;
}

.admin-user-badge {
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 用戶名輸入界面樣式 */
.chat-name-input {
    padding: 30px 20px;
    text-align: center;
    background: #f8f9fa;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.name-input-content h4 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.name-input-content p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.name-input-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 250px;
    margin: 0 auto;
}

.name-input {
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
    outline: none;
}

.name-input:focus {
    border-color: #5374f8;
}

.name-confirm-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, #5374f8 0%, #232369 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.name-confirm-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(83, 116, 248, 0.3);
}

.name-confirm-btn:active {
    transform: translateY(0);
}

/* 聊天內容區域 - 強化版布局修復 */
.chat-content {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0 !important; /* 重要：確保 flex 子元素可以收縮 */
    max-height: 100% !important;
    overflow: hidden !important;
}

/* 消息發送者名稱顯示 */
.chat-message-sender {
    font-size: 11px;
    color: #666;
    margin-bottom: 4px;
    font-weight: 500;
}

.chat-message.admin .chat-message-sender {
    color: #888;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .chat-window {
        width: 300px;
        height: 450px;
        bottom: 90px;
        right: 10px;
    }
    
    .admin-chat-window {
        width: 320px;
        height: 500px;
        bottom: 90px;
        right: 10px;
    }
}

@media (max-width: 480px) {
    .chat-window,
    .admin-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 120px);
        right: 10px;
        left: 10px;
        bottom: 80px;
    }
    
    .chat-name-input {
        padding: 20px 15px;
        min-height: 180px;
    }
    
    .name-input-group {
        max-width: 200px;
    }
    
    .name-input-content h4 {
        font-size: 16px;
    }
    
    .name-input-content p {
        font-size: 13px;
    }
}

/* 動畫效果 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-window.open {
    animation: fadeInUp 0.3s ease;
}

.chat-message {
    animation: fadeInUp 0.2s ease;
}

/* 滾動條樣式 */
.chat-messages::-webkit-scrollbar,
.admin-user-list::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.admin-user-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb,
.admin-user-list::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.admin-user-list::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Chat Translation Styles */

/* Translation Controls */
.chat-translation-controls, .admin-translation-controls {
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    padding: 10px 15px;
    font-size: 12px;
}

.translation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.translation-header span {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    color: #495057;
}

.translation-icon {
    font-size: 14px;
}

.translation-toggle {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.translation-toggle:hover {
    background: #0056b3;
}

.translation-options, .admin-translation-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.language-selector label {
    font-size: 11px;
    color: #6c757d;
    min-width: 60px;
}

.language-selector select {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 11px;
    background: white;
}

.translation-toggle-text {
    display: flex;
    align-items: center;
}

.translation-toggle-text label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #6c757d;
    cursor: pointer;
}

.translation-toggle-text input[type="checkbox"] {
    margin: 0;
}

/* Message Translation Buttons */
.chat-message-translation {
    margin-top: 5px;
}

.translation-toggle-btn {
    background: none;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 10px;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 3px;
}

.translation-toggle-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
    color: #495057;
}

.translation-toggle-btn i {
    font-size: 9px;
}

/* Admin Translation Controls Specific Styles */
.admin-translation-controls {
    background: #e3f2fd;
    border-bottom: 1px solid #bbdefb;
}

.admin-translation-controls .translation-toggle {
    background: #1976d2;
}

.admin-translation-controls .translation-toggle:hover {
    background: #1565c0;
}

/* Translation Status Indicators */
.chat-message.user .translation-toggle-btn {
    background: rgba(0, 123, 255, 0.1);
    border-color: rgba(0, 123, 255, 0.3);
    color: #007bff;
}

.chat-message.admin .translation-toggle-btn {
    background: rgba(40, 167, 69, 0.1);
    border-color: rgba(40, 167, 69, 0.3);
    color: #28a745;
}

/* Responsive adjustments for mobile */
@media (max-width: 480px) {
    .chat-translation-controls, .admin-translation-controls {
        padding: 8px 10px;
    }
    
    .translation-header {
        margin-bottom: 6px;
    }
    
    .translation-options, .admin-translation-options {
        gap: 6px;
    }
    
    .language-selector {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .language-selector label {
        min-width: auto;
    }
    
    .language-selector select {
        width: 100%;
    }
}
