/* Chat Widget Styles - Glassmorphism & Site Theme Match */
:root {
    --chat-primary: #5b7cff;
    --chat-primary-2: #8b5cf6;
    --chat-bg: rgba(16, 18, 28, 0.82);
    --chat-panel: rgba(0, 0, 0, 0.18);
    --chat-text: rgba(255, 255, 255, 0.92);
    --chat-text-secondary: rgba(148, 163, 184, 0.92);
    --chat-bubble-me: #5b7cff;
    --chat-bubble-other: rgba(255, 255, 255, 0.08);
    --chat-border-color: rgba(255, 255, 255, 0.10);
    --chat-border: 1px solid var(--chat-border-color);
    --chat-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
    --chat-radius: 22px;
}

/* Launcher Button */
.chat-widget-launcher {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-2));
    border-radius: 50%;
    box-shadow: 0 10px 30px rgba(91, 124, 255, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.15);
}

.chat-widget-launcher:hover {
    transform: translateY(-2px) scale(1.06);
    box-shadow: 0 16px 40px rgba(91, 124, 255, 0.45);
}

.chat-widget-launcher:active {
    transform: translateY(0) scale(0.98);
}

.chat-widget-launcher i {
    color: white;
    font-size: 30px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.unread-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ef4444;
    color: white;
    font-size: 0.72rem;
    font-weight: 800;
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(16, 18, 28, 0.9);
    box-shadow: 0 10px 22px rgba(239, 68, 68, 0.28);
    animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10000;
    padding: 0 6px;
}

@keyframes popIn {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

.chat-widget-container {
    position: fixed;
    bottom: 104px;
    right: 24px;
    width: 400px;
    height: 640px;
    max-height: min(82vh, 720px);
    background:
        radial-gradient(900px 520px at 15% 0%, rgba(91, 124, 255, 0.10), transparent 55%),
        radial-gradient(800px 480px at 85% 18%, rgba(139, 92, 246, 0.10), transparent 60%),
        var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    transform: translateY(18px) scale(0.96);
    transform-origin: bottom right;
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.28s ease;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.10);
    overflow: hidden;
}

.chat-widget-container.active {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Header */
.chat-header {
    padding: 20px 22px;
    background: linear-gradient(135deg, rgba(91, 124, 255, 0.22), rgba(139, 92, 246, 0.18));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--chat-text);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info h3 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.4px;
    line-height: 1;
}

.chat-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    padding: 4px 10px;
    border-radius: 99px;
    backdrop-filter: blur(4px);
}

.chat-status-text {
    font-size: 0.72rem;
    font-weight: 700;
    color: #10b981;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-dot {
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
    position: relative;
}

.status-dot::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: inherit;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    70% {
        transform: scale(2.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 0;
    }
}

/* 在线状态样式 */
.chat-status-badge.online {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.25);
}

.chat-status-badge.online .chat-status-text {
    color: #10b981;
}

.chat-status-badge.online .status-dot {
    background: #10b981;
}

/* 离线状态样式 */
.chat-status-badge.offline {
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.25);
}

.chat-status-badge.offline .chat-status-text {
    color: #94a3b8;
}

.chat-status-badge.offline .status-dot {
    background: #94a3b8;
}

.status-dot.offline::after {
    animation: none;
}

.chat-hours {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: rgba(203, 213, 225, 0.85);
    font-weight: 500;
}

.chat-hours i {
    font-size: 0.78rem;
    opacity: 0.7;
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.18);
    transform: rotate(90deg) scale(1.02);
}

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

/* Messages Area */
.chat-messages {
    flex: 1;
    padding: 18px 16px;
    overflow-y: auto;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    transition: background 0.3s;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.message {
    max-width: 85%;
    min-width: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease;
    box-sizing: border-box;
}

.message.visitor {
    align-self: flex-end;
    align-items: flex-end;
}

.message.agent {
    align-self: flex-start;
    align-items: flex-start;
}

.message-bubble {
    padding: 0.8rem 1.2rem;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
}

/* 附件消息的气泡 padding 调整 */
.message-bubble:has(.message-attachment) {
    padding: 0.8rem;
    line-height: 0;
    white-space: normal;
}

.message-bubble:has(.message-attachment) .message-attachment {
    line-height: normal;
    white-space: normal;
}

.message.visitor .message-bubble {
    background: var(--chat-bubble-me);
    /* Blue */
    color: white;
    border-bottom-right-radius: 4px;
    background: linear-gradient(135deg, #5b7cff, #4a6bff);
}

.message.agent .message-bubble {
    background: var(--chat-bubble-other);
    /* Dark glass */
    color: var(--chat-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 6px;
    margin-left: 4px;
}

.message.visitor .message-time {
    margin-right: 4px;
    text-align: right;
}

/* 已读/未读状态标签 */
.message-read-status {
    font-size: 0.7rem;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    font-weight: 500;
    display: inline-block;
}

.message-read-status.read {
    color: #10b981;
    background: rgba(16, 185, 129, 0.15);
}

.message-read-status.unread {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
}

/* Input Area */
.chat-input-area {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: var(--chat-border);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    backdrop-filter: blur(10px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

.chat-input-area.emoji-picker-active {
    transform: translateY(-280px);
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
    padding: 8px;
    border-radius: 50%;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.action-btn.emoji-btn.active {
    background: rgba(91, 124, 255, 0.2);
    color: #9db0ff;
    border: 1px solid rgba(91, 124, 255, 0.3);
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
    color: white;
    outline: none;
    transition: all 0.2s;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 2px rgba(91, 124, 255, 0.2);
}

.send-btn {
    background: linear-gradient(135deg, #5b7cff, #4a6bff);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(91, 124, 255, 0.3);
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(91, 124, 255, 0.4);
}

.send-btn:active {
    transform: scale(0.95);
}

/* Image Preview */
.message-image {
    max-width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Video Message Styles */
.message-video {
    max-width: 100%;
}

.message-video video {
    max-width: 100%;
    max-height: 280px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
}

.message-video-meta {
    margin-bottom: 4px;
}

/* Attachment Message Styles - 参考 internal-chat 成员沟通聊天框的配色方案 */
.message-attachment {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    max-width: 100%;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.2s ease;
    overflow: hidden;
    flex-shrink: 1;
    margin-top: 0.5rem;
}

/* 访客消息（左侧）的附件样式 - 蓝色主题 */
.message.visitor .message-attachment {
    background: rgba(91, 124, 255, 0.08);
    border: 1px solid rgba(91, 124, 255, 0.2);
    box-shadow: 0 2px 8px rgba(91, 124, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.message.visitor .message-attachment:hover {
    background: rgba(91, 124, 255, 0.12);
    border-color: rgba(91, 124, 255, 0.3);
    box-shadow: 0 4px 12px rgba(91, 124, 255, 0.15);
    transform: translateY(-1px);
}

/* 客服消息（右侧）的附件样式 - 橙色主题 */
.message.agent .message-attachment {
    background: rgba(255, 149, 0, 0.15);
    border: 1px solid rgba(255, 149, 0, 0.4);
    box-shadow: 0 2px 8px rgba(255, 149, 0, 0.2);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.message.agent .message-attachment:hover {
    background: rgba(255, 149, 0, 0.2);
    border-color: rgba(255, 149, 0, 0.5);
    box-shadow: 0 4px 12px rgba(255, 149, 0, 0.25);
    transform: translateY(-1px);
}

.attachment-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.2rem;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* 访客消息的附件图标样式 - 蓝色 */
.message.visitor .attachment-icon {
    background: rgba(91, 124, 255, 0.15);
    border: 1px solid rgba(91, 124, 255, 0.25);
    color: #5b7cff;
}

/* 客服消息的附件图标样式 - 橙色 */
.message.agent .attachment-icon {
    background: rgba(255, 149, 0, 0.25);
    border: 1px solid rgba(255, 149, 0, 0.4);
    color: #ffffff;
}

.attachment-info {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.attachment-name {
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: break-all;
    max-width: 100%;
    min-width: 0;
}

/* 访客消息的附件名称样式 */
.message.visitor .attachment-name {
    color: #1a1a1a;
}

/* 客服消息的附件名称样式 */
.message.agent .attachment-name {
    color: #ffffff;
}

.attachment-meta {
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    word-break: break-all;
    max-width: 100%;
    min-width: 0;
    margin-top: 0.25rem;
}

/* 访客消息的附件元信息样式 */
.message.visitor .attachment-meta {
    color: #666666;
    font-weight: 500;
}

/* 客服消息的附件元信息样式 */
.message.agent .attachment-meta {
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.attachment-download {
    font-size: 1.1rem;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.3s ease;
    flex-shrink: 0;
    text-decoration: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 访客消息的下载按钮样式 - 蓝色 */
.message.visitor .attachment-download {
    color: #5b7cff;
    background: rgba(91, 124, 255, 0.1);
    border-radius: 8px;
}

.message.visitor .attachment-download:hover {
    background: rgba(91, 124, 255, 0.2);
    color: #4a6bff;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(91, 124, 255, 0.25);
}

/* 客服消息的下载按钮样式 - 橙色 */
.message.agent .attachment-download {
    color: rgba(255, 255, 255, 0.95);
    background: rgba(255, 149, 0, 0.2);
    border-radius: 8px;
}

.message.agent .attachment-download:hover {
    background: rgba(255, 149, 0, 0.35);
    color: white;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(255, 149, 0, 0.3);
}

/* Upload Progress Bubble */
.upload-progress-bubble {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.upload-progress-text {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
}

.upload-progress-bar {
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    overflow: hidden;
}

.upload-progress-bar-inner {
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #5b7cff, #8b5cf6);
    transition: width 0.15s ease-out;
}

.upload-progress-bar-inner.error {
    background: #ef4444;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Emoji Picker */
.chat-emoji-picker {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 280px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    pointer-events: none;
    border-radius: 0 0 var(--chat-radius) var(--chat-radius);
}

.chat-emoji-picker.active {
    transform: translateY(0);
    pointer-events: auto;
}

.chat-emoji-picker-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    gap: 1rem;
    flex-shrink: 0;
}

.chat-emoji-picker-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    flex-shrink: 0;
    letter-spacing: -0.01em;
}

.chat-emoji-picker-tabs {
    display: flex;
    background: transparent;
    gap: 0.25rem;
    flex: 1;
    justify-content: flex-end;
    align-items: center;
}

.chat-emoji-tab {
    background: transparent;
    border: none;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgba(148, 163, 184, 0.8);
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.chat-emoji-tab:hover {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}

.chat-emoji-tab.active {
    color: #9db0ff;
    background: rgba(91, 124, 255, 0.15);
    font-weight: 600;
}

.chat-btn-close-emoji {
    background: transparent;
    border: none;
    color: rgba(148, 163, 184, 0.8);
    cursor: pointer;
    padding: 0.375rem;
    border-radius: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.875rem;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-btn-close-emoji:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.9);
    transform: rotate(90deg);
}

.chat-emoji-picker-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
    align-content: start;
    background: rgba(0, 0, 0, 0.1);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.chat-emoji-picker-content::-webkit-scrollbar {
    width: 6px;
}

.chat-emoji-picker-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-emoji-picker-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-emoji-picker-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-emoji-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    background: rgba(255, 255, 255, 0.03);
    border: 2px solid transparent;
    box-sizing: border-box;
}

.chat-emoji-item:hover {
    background: rgba(91, 124, 255, 0.15);
    border-color: rgba(91, 124, 255, 0.3);
    transform: scale(1.1);
}

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

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-widget-container {
        width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        transform-origin: center;
    }
}