/**
 * ECC 智能客服样式 — v2.0 全面升级版
 * 2026-04-15
 * 品牌色：#0052D9（与首页子主题完全统一）
 */

/* ========== CSS变量（品牌统一）============ */
:root {
    --chat-primary:        #0052D9;
    --chat-primary-dark:   #0040B4;
    --chat-primary-light:  #1A6EFF;
    --chat-primary-pale:   #E8F0FE;
    --chat-primary-glow:   rgba(0, 82, 217, 0.22);
    --chat-text-dark:      #111827;
    --chat-text-body:      #374151;
    --chat-text-muted:     #6B7280;
    --chat-bg-page:        #F4F6FA;
    --chat-bg-card:        #FFFFFF;
    --chat-bg-subtle:      #F8FAFC;
    --chat-border:         #E5E7EB;
    --chat-border-soft:    #F1F3F8;
    --chat-success:        #10B981;
    --chat-danger:         #EF4444;
    --chat-warning:        #F59E0B;
    --chat-shadow-xs:      0 1px 3px rgba(0,0,0,.06);
    --chat-shadow-sm:      0 2px 8px rgba(0,0,0,.07);
    --chat-shadow-md:      0 4px 20px rgba(0,0,0,.09);
    --chat-shadow-lg:      0 8px 40px rgba(0,0,0,.14);
    --chat-shadow-primary: 0 6px 28px rgba(0,82,217,.38);
    --chat-shadow-primary-sm: 0 3px 14px rgba(0,82,217,.28);
    --chat-radius-sm:      6px;
    --chat-radius-md:      10px;
    --chat-radius-lg:      16px;
    --chat-radius-xl:      24px;
    --chat-radius-full:    9999px;
    --chat-ease:           cubic-bezier(0.16, 1, 0.3, 1);
    --chat-ease-in-out:    cubic-bezier(0.45, 0, 0.55, 1);
    --chat-duration:       280ms;
    --chat-duration-fast:  160ms;
    --chat-duration-slow:  420ms;
    --chat-font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

/* ========== 悬浮气泡按钮 ========== */
.ecc-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chat-shadow-primary);
    z-index: 9998;
    border: 3px solid rgba(255,255,255,.15);
    transition:
        transform var(--chat-duration) var(--chat-ease),
        box-shadow var(--chat-duration) var(--chat-ease),
        background var(--chat-duration-fast) ease;
    outline: none;
}

.ecc-chat-bubble:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 10px 40px rgba(0,82,217,.44), 0 0 0 6px var(--chat-primary-pale);
    background: var(--chat-primary-dark);
}

.ecc-chat-bubble:active {
    transform: scale(1.05) translateY(0);
    box-shadow: var(--chat-shadow-primary-sm);
}

/* 气泡内图标 */
.ecc-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform var(--chat-duration) var(--chat-ease);
}

.ecc-chat-bubble:hover svg {
    transform: scale(1.1);
}

/* 气泡打开后：图标变为 ✕ */
.ecc-chat-bubble.is-open::after {
    content: '✕';
    position: absolute;
    font-size: 20px;
    color: white;
    line-height: 1;
}

/* 隐藏原始 SVG 当打开时 */
.ecc-chat-bubble.is-open svg {
    display: none;
}

/* 未读消息红点 */
.ecc-chat-bubble .ecc-bubble-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--chat-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: eccBadgePop .4s var(--chat-ease) both;
}

@keyframes eccBadgePop {
    0%   { transform: scale(0); }
    70%  { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* ========== 聊天窗口容器 ========== */
.ecc-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 100px);
    background: var(--chat-bg-card);
    border-radius: var(--chat-radius-xl);
    box-shadow: var(--chat-shadow-lg), 0 0 0 1px rgba(0,0,0,.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    font-family: var(--chat-font);
    outline: none;

    /* 默认隐藏 + 入场动画 */
    display: none;
    opacity: 0;
    transform: translateY(24px) scale(.9);
    transform-origin: bottom right;
    transition:
        opacity var(--chat-duration-slow) var(--chat-ease),
        transform var(--chat-duration-slow) var(--chat-ease);
}

.ecc-chat-widget.active {
    display: flex;
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* 最大化状态由 JS 直接设置内联样式控制，不再依赖此 CSS 类 */

/* 关闭动画 */
.ecc-chat-widget.closing {
    opacity: 0;
    transform: translateY(16px) scale(.92);
    transition:
        opacity var(--chat-duration) var(--chat-ease-in-out),
        transform var(--chat-duration) var(--chat-ease-in-out);
}


/* ========== 头部栏 ========== */
.ecc-chat-header {
    padding: 0;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    height: 60px;
    padding: 0 16px 0 20px;
    position: relative;
    overflow: hidden;
}

/* 头部装饰圆 */
.ecc-chat-header::before {
    content: '';
    position: absolute;
    top: -20px;
    right: -20px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,.06);
}

.ecc-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.ecc-chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    border: 2px solid rgba(255,255,255,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
}

.ecc-chat-header-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ecc-chat-header-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.ecc-chat-header-status {
    font-size: 11px;
    color: rgba(255,255,255,.7);
    display: flex;
    align-items: center;
    gap: 5px;
}

.ecc-chat-header-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: eccStatusPulse 2s ease-in-out infinite;
}

@keyframes eccStatusPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .7; transform: scale(.85); }
}

.ecc-chat-header-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    position: relative;
    z-index: 1;
}

.ecc-chat-header-buttons button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,.12);
    color: rgba(255,255,255,.85);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background var(--chat-duration-fast) ease,
        color var(--chat-duration-fast) ease,
        transform var(--chat-duration-fast) ease;
    line-height: 1;
}

.ecc-chat-header-buttons button:hover {
    background: rgba(255,255,255,.22);
    color: #fff;
    transform: scale(1.1);
}

.ecc-chat-header-buttons button:active {
    transform: scale(.95);
}

.ecc-chat-header-buttons button.ecc-header-close:hover {
    background: rgba(239,68,68,.7);
    color: #fff;
}

/* ========== 消息区域 ========== */
.ecc-chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.ecc-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--chat-bg-page);
    font-size: 14px;
    line-height: 1.65;
    min-height: 0;
    scroll-behavior: smooth;
}

.ecc-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.ecc-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.ecc-chat-messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 2px;
}
.ecc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-text-muted);
}

/* ========== 消息气泡 ========== */
.ecc-chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 14px;
    animation: eccMsgSlideIn var(--chat-duration) var(--chat-ease) both;
}

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

/* 用户消息靠右 */
.ecc-chat-message.user {
    flex-direction: row-reverse;
}

/* 头像 */
.ecc-chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    box-shadow: var(--chat-shadow-xs);
    border: 2px solid white;
}

.ecc-chat-message.user .ecc-chat-message-avatar {
    background: var(--chat-success);
    border-color: white;
    order: 1;
}

/* 消息内容区 */
.ecc-chat-message-content {
    max-width: 76%;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* 气泡 */
.ecc-chat-message-bubble {
    padding: 10px 14px;
    border-radius: var(--chat-radius-md);
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.65;
    position: relative;
    box-shadow: var(--chat-shadow-xs);
    transition: box-shadow var(--chat-duration-fast) ease;
}

/* AI 气泡：白底，左上圆角尖角 */
.ecc-chat-message.assistant .ecc-chat-message-bubble {
    background: var(--chat-bg-card);
    border: 1px solid var(--chat-border-soft);
    border-radius: var(--chat-radius-md) var(--chat-radius-md) var(--chat-radius-md) 4px;
    color: var(--chat-text-body);
}

/* AI 气泡尖角 */
.ecc-chat-message.assistant .ecc-chat-message-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -7px;
    width: 0;
    height: 0;
    border-top: 0;
    border-right: 8px solid var(--chat-border-soft);
    border-bottom: 8px solid transparent;
    border-left: 0;
}

.ecc-chat-message.assistant .ecc-chat-message-bubble::after {
    content: '';
    position: absolute;
    top: 1px;
    left: -5px;
    width: 0;
    height: 0;
    border-top: 0;
    border-right: 6px solid var(--chat-bg-card);
    border-bottom: 6px solid transparent;
    border-left: 0;
}

/* 用户气泡：品牌色底，右上圆角尖角 */
.ecc-chat-message.user .ecc-chat-message-bubble {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-light) 100%);
    color: white;
    border-radius: var(--chat-radius-md) var(--chat-radius-md) 4px var(--chat-radius-md);
    box-shadow: var(--chat-shadow-primary-sm);
}

/* 用户气泡尖角 */
.ecc-chat-message.user .ecc-chat-message-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    right: -7px;
    width: 0;
    height: 0;
    border-top: 0;
    border-left: 8px solid var(--chat-primary-light);
    border-bottom: 8px solid transparent;
}

.ecc-chat-message.user .ecc-chat-message-bubble::after {
    content: '';
    position: absolute;
    top: 1px;
    right: -5px;
    width: 0;
    height: 0;
    border-top: 0;
    border-left: 6px solid var(--chat-primary);
    border-bottom: 6px solid transparent;
}

/* 时间戳 */
.ecc-chat-message-time {
    font-size: 11px;
    color: var(--chat-text-muted);
    padding: 0 4px;
}

.ecc-chat-message.user .ecc-chat-message-time {
    text-align: right;
}

/* ========== 打字指示器 ========== */
.ecc-chat-typing-indicator {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 14px;
}

.ecc-chat-typing-indicator .ecc-chat-message-bubble {
    padding: 12px 16px;
    background: var(--chat-bg-card);
    border: 1px solid var(--chat-border-soft);
    border-radius: var(--chat-radius-md) var(--chat-radius-md) var(--chat-radius-md) 4px;
    box-shadow: var(--chat-shadow-xs);
}

.ecc-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 0;
}

.ecc-chat-typing span {
    display: block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-text-muted);
    animation: eccTypingBounce 1.3s ease-in-out infinite;
}

.ecc-chat-typing span:nth-child(1) { animation-delay: 0ms; }
.ecc-chat-typing span:nth-child(2) { animation-delay: 180ms; }
.ecc-chat-typing span:nth-child(3) { animation-delay: 360ms; }

@keyframes eccTypingBounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: .4; }
    30%            { transform: translateY(-7px); opacity: 1; }
}

/* ========== 底部操作区 ========== */
.ecc-chat-bottom {
    padding: 12px 14px 14px;
    background: var(--chat-bg-card);
    border-top: 1px solid var(--chat-border-soft);
    flex-shrink: 0;
}

/* 快捷按钮区 */
.ecc-chat-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

/* [优化] 快捷按钮：品牌色主题胶囊 */
.ecc-chat-quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: var(--chat-radius-full);
    border: 1.5px solid var(--chat-border);
    background: var(--chat-bg-subtle);
    font-size: 12px;
    font-weight: 600;
    font-family: var(--chat-font);
    color: var(--chat-text-body);
    cursor: pointer;
    white-space: nowrap;
    transition:
        background var(--chat-duration-fast) ease,
        border-color var(--chat-duration-fast) ease,
        color var(--chat-duration-fast) ease,
        transform var(--chat-duration-fast) ease,
        box-shadow var(--chat-duration-fast) ease;
    letter-spacing: .01em;
    -webkit-tap-highlight-color: transparent;
}

.ecc-chat-quick-btn:hover {
    background: var(--chat-primary-pale);
    border-color: var(--chat-primary);
    color: var(--chat-primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--chat-primary-glow);
}

.ecc-chat-quick-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.ecc-chat-quick-btn .btn-icon {
    font-size: 12px;
    flex-shrink: 0;
}

/* 输入框行 */
.ecc-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}

/* [优化] 输入框：聚焦品牌色光晕 */
#ecc-chat-input {
    flex: 1;
    padding: 11px 16px;
    border-radius: var(--chat-radius-full);
    border: 1.5px solid var(--chat-border);
    font-size: 14px;
    font-family: var(--chat-font);
    color: var(--chat-text-dark);
    background: var(--chat-bg-subtle);
    outline: none;
    min-width: 0;
    transition:
        border-color var(--chat-duration-fast) ease,
        box-shadow var(--chat-duration-fast) ease,
        background var(--chat-duration-fast) ease;
    -webkit-appearance: none;
    appearance: none;
}

#ecc-chat-input::placeholder {
    color: #9CA3AF;
}

#ecc-chat-input:focus {
    border-color: var(--chat-primary);
    background: var(--chat-bg-card);
    box-shadow: 0 0 0 3px var(--chat-primary-glow);
}

/* [优化] 发送按钮：品牌色 + hover动效 */
.ecc-send-primary {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    padding: 11px 20px;
    border-radius: var(--chat-radius-full);
    font-size: 13px;
    font-weight: 700;
    font-family: var(--chat-font);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    letter-spacing: .01em;
    box-shadow: var(--chat-shadow-primary-sm);
    transition:
        background var(--chat-duration-fast) ease,
        transform var(--chat-duration-fast) ease,
        box-shadow var(--chat-duration-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.ecc-send-primary:hover:not(:disabled) {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--chat-shadow-primary);
}

.ecc-send-primary:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--chat-shadow-primary-sm);
}

.ecc-send-primary:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* 发送按钮图标 */
.ecc-send-icon {
    width: 16px;
    height: 16px;
    fill: currentColor;
    transition: transform var(--chat-duration-fast) ease;
}

.ecc-send-primary:hover:not(:disabled) .ecc-send-icon {
    transform: translateX(2px);
}

/* ========== 消息入场动画延迟 ========== */
.ecc-chat-message:nth-child(1)  { animation-delay: 0ms; }
.ecc-chat-message:nth-child(2)  { animation-delay: 50ms; }
.ecc-chat-message:nth-child(3)  { animation-delay: 100ms; }
.ecc-chat-message:nth-child(n+4) { animation-delay: 0ms; }

/* ========== 气泡 hover 效果 ========== */
.ecc-chat-message-bubble:hover {
    box-shadow: var(--chat-shadow-sm);
}

/* ========== 报价卡片（在消息气泡内） ========== */
.ecc-chat-quote-card {
    background: var(--chat-bg-subtle);
    border: 1px solid var(--chat-border-soft);
    border-radius: var(--chat-radius-md);
    padding: 12px;
    margin-top: 6px;
    font-size: 13px;
}

.ecc-chat-quote-card-title {
    font-weight: 700;
    color: var(--chat-primary);
    font-size: 13px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* ========== 报价表格 ========== */
.ecc-quote-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    line-height: 1.5;
}

.ecc-quote-table thead {
    background: var(--chat-primary-pale);
}

.ecc-quote-table th {
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--chat-primary);
    border-bottom: 1.5px solid var(--chat-border);
    white-space: nowrap;
    font-size: 11px;
}

.ecc-quote-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--chat-border-soft);
    color: var(--chat-text-body);
    vertical-align: top;
}

.ecc-quote-table tbody tr:last-child td {
    border-bottom: none;
}

.ecc-quote-table tbody tr:hover {
    background: var(--chat-bg-subtle);
}

.ecc-quote-channel {
    font-weight: 600;
    color: var(--chat-text-dark);
    white-space: nowrap;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ecc-quote-total strong {
    color: var(--chat-primary);
    font-size: 13px;
}

/* 报价底部跳转提示 */
.ecc-quote-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--chat-border);
    font-size: 12px;
    color: var(--chat-text-muted);
}

.ecc-quote-link-btn {
    display: inline-block;
    padding: 4px 12px;
    background: var(--chat-primary-pale);
    color: var(--chat-primary);
    border-radius: var(--chat-radius-sm);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    transition: background var(--chat-duration-fast) ease;
    white-space: nowrap;
}

.ecc-quote-link-btn:hover {
    background: var(--chat-primary);
    color: #fff;
}

/* 联系客服按钮 */
.ecc-contact-btn-wrap {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--chat-border);
    text-align: center;
}
.ecc-contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    background: var(--chat-primary);
    color: #fff;
    border-radius: var(--chat-radius-sm);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--chat-duration-fast) ease, transform var(--chat-duration-fast) ease;
}
.ecc-contact-btn:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

/* 运费查询页跳转按钮 */
.ecc-query-btn-wrap {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--chat-border);
    text-align: center;
}
.ecc-query-tip {
    display: block;
    font-size: 12px;
    color: var(--chat-text-muted);
    margin-bottom: 6px;
}
.ecc-query-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    background: var(--chat-primary);
    color: #fff;
    border-radius: var(--chat-radius-sm);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--chat-duration-fast) ease, transform var(--chat-duration-fast) ease;
}
.ecc-query-btn:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

/* 报价气泡放宽，容纳表格 */
.ecc-chat-message.assistant .ecc-chat-message-content {
    max-width: 92%;
}

/* 移动端表格横向滚动 */
@media (max-width: 480px) {
    .ecc-chat-quote-card {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 8px;
    }
    .ecc-quote-table {
        min-width: 480px;
    }
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .ecc-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .ecc-chat-widget {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
        max-width: 100vw;
        transform-origin: bottom center;
    }

    .ecc-chat-widget.active {
        transform: translateY(0) scale(1);
    }

    /* 手机上隐藏最大化按钮 */
    .ecc-chat-header-buttons #ecc-maximize {
        display: none;
    }

    .ecc-chat-messages {
        padding: 12px;
    }

    .ecc-chat-message-content {
        max-width: 82%;
    }
}

@media (max-width: 400px) {
    .ecc-chat-quick-btn {
        padding: 5px 10px;
        font-size: 11px;
    }
}
