/* 聊天小部件样式 */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 聊天按钮（已废弃：统一走右侧快捷栏「客服」入口） */
.chat-toggle-btn {
    display: none !important;
}

/* 聊天弹窗 */
.chat-popup {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e1e5e9;
}

.chat-popup.show {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

.chat-widget--docked .chat-popup {
    position: fixed;
    top: auto;
    right: 76px;
    bottom: 20px;
    transform: none;
}

.chat-widget--docked .chat-popup.show {
    animation: chatDockFade 0.2s ease-out;
}

@keyframes chatDockFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 聊天头部 */
.chat-header {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-close-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.32);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
    display: block;
}

.chat-message.user {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%) !important;
    color: white !important;
    align-self: flex-end !important;
    margin-left: auto;
    margin-right: 0;
    border-bottom-right-radius: 4px;
}

.chat-message.has-image {
    padding: 6px;
    background: #fff !important;
    border: 1px solid #e1e5e9;
    max-width: 42%;
}

.chat-message-image {
    display: block;
    max-width: 140px;
    max-height: 160px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: contain;
    border: 1px solid transparent;
}

.chat-message-image.is-selected {
    border-color: #2196F3;
    box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.25);
}

.chat-message.bot {
    background: white !important;
    color: #333 !important;
    align-self: flex-start !important;
    margin-left: 0;
    margin-right: auto;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
}

.chat-message.bot.has-product {
    max-width: 92%;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
}

.chat-product-bundle {
    background: #fff;
    border: 1px solid #f0f0f0;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    min-width: 240px;
    max-width: 300px;
}

.chat-product-bundle-text {
    font-size: 14px;
    color: #262626;
    line-height: 1.5;
    margin-bottom: 10px;
}

.chat-product-links {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-product-card {
    display: block;
    color: inherit;
    text-decoration: none;
    border: 1px solid #f5f5f5;
    border-radius: 8px;
    padding: 8px;
    background: #fafafa;
    line-height: 1.4;
    word-break: break-word;
}

.chat-product-card:hover {
    border-color: #ffd8bf;
    background: #fffaf7;
}

.chat-product-card-main {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.chat-product-card-thumb {
    width: 72px;
    height: 72px;
    border-radius: 6px;
    object-fit: cover;
    background: #fff;
    flex-shrink: 0;
}

.chat-product-card-thumb.is-placeholder {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #bfbfbf;
    font-size: 12px;
    background: #f5f5f5;
}

.chat-product-card-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    justify-content: center;
}

.chat-product-card-title {
    font-weight: 600;
    color: #1f1f1f;
    font-size: 14px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
}

a.chat-product-card-title:hover {
    color: #fa541c;
}

.chat-product-bundle-actions {
    margin-top: 12px;
}

.chat-product-bundle-action {
    width: 100%;
    height: 36px;
    border: 0;
    border-radius: 18px;
    background: #ff7a45;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    cursor: pointer;
    padding: 0 8px;
}

.chat-product-bundle-action:hover {
    background: #fa541c;
    color: #fff;
}

.chat-product-bundle-remark {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #f0f0f0;
    font-size: 12px;
    color: #8c8c8c;
    line-height: 1.4;
    word-break: break-word;
}

.chat-product-link-disabled {
    color: #666;
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 6px 8px;
    background: #f8f8f8;
}

.chat-inline-link {
    color: #1976D2;
    text-decoration: underline;
    word-break: break-all;
}

.chat-inline-link:hover {
    color: #0d47a1;
}

/* 聊天输入区域 */
.chat-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-image-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #ddd;
    border-radius: 50%;
    background: #fff;
    color: #666;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.chat-image-btn:hover {
    color: #2196F3;
    border-color: #2196F3;
    background: #e3f2fd;
}

.chat-input-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-pending-images {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    border: 1px dashed #d0d5dd;
    border-radius: 10px;
    background: #fafafa;
}

.chat-pending-images.has-items {
    display: flex;
}

.chat-pending-label {
    font-size: 11px;
    color: #888;
    line-height: 1.3;
}

.chat-pending-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-pending-image {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #ddd;
    background: #fff;
}

.chat-pending-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-pending-image-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 14px;
    line-height: 18px;
    cursor: pointer;
    padding: 0;
}

.chat-pending-image-remove:hover {
    background: rgba(0, 0, 0, 0.75);
}

.chat-input-wrap {
    flex: 1;
    min-width: 0;
}

.chat-input {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.chat-input:focus {
    border-color: #2196F3;
}

.chat-input-count {
    margin-top: 4px;
    padding-right: 8px;
    text-align: right;
    font-size: 12px;
    color: #999;
    line-height: 1;
}

.chat-input-count.is-limit {
    color: #d93025;
}

.chat-send-btn {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 欢迎消息 */
.welcome-message {
    text-align: center;
    color: #666;
    font-size: 14px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    margin: 10px 0;
}

/* 加载状态 */
.chat-loading {
    text-align: center;
    color: #666;
    font-size: 14px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    margin: 10px 0;
}

/* 响应式设计 */
@media (max-width: 480px) {
    .chat-widget {
        right: 10px;
        bottom: 90px;
    }

    .chat-popup {
        position: absolute;
        top: auto;
        left: auto;
        right: 0;
        bottom: 60px;
        width: min(340px, calc(100vw - 20px));
        height: min(520px, calc(100dvh - 160px));
        max-height: calc(100dvh - 160px);
        border-radius: 12px;
        border: 1px solid #e1e5e9;
    }

    .chat-popup.show {
        animation: slideUp 0.3s ease-out;
    }

    .chat-messages {
        padding: 14px;
        overscroll-behavior: contain;
    }

    .chat-input-area {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .chat-input {
        font-size: 16px;
    }
}

@media (max-width: 768px) {
    .chat-widget--docked .chat-popup {
        position: fixed;
        top: auto;
        right: 56px;
        bottom: 12px;
        width: min(350px, calc(100vw - 70px));
        height: min(500px, calc(100dvh - 24px));
        max-height: calc(100dvh - 24px);
        transform: none;
    }

    .chat-widget--docked .chat-popup.show {
        animation: chatDockFade 0.2s ease-out;
    }
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
