/* =============================================
   十方纳福 AI 聊天挂件样式
   Chinese traditional aesthetic theme
   ============================================= */

/* --- CSS 变量 --- */
:root {
    --cw-primary: #8B4513;
    --cw-primary-light: #A0522D;
    --cw-accent: #D4A76A;
    --cw-accent-light: #E8D5B7;
    --cw-bg: #FFF8F0;
    --cw-bg-light: #FDF5EC;
    --cw-text: #3E2723;
    --cw-text-light: #6D4C41;
    --cw-border: #D7CCC8;
    --cw-white: #FFFFFF;
    --cw-user-bubble: #1976D2;
    --cw-user-text: #FFFFFF;
    --cw-bot-bubble: #F5F0E8;
    --cw-bot-text: #3E2723;
    --cw-shadow: 0 4px 24px rgba(62, 39, 35, 0.15);
    --cw-shadow-lg: 0 8px 40px rgba(62, 39, 35, 0.2);
    --cw-radius: 16px;
    --cw-radius-sm: 8px;
    --cw-z: 999998;
}

/* --- 浮动按钮 --- */
.chat-widget-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-light));
    color: #FFF;
    border: none;
    cursor: pointer;
    box-shadow: var(--cw-shadow-lg);
    z-index: var(--cw-z);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-size: 28px;
    -webkit-tap-highlight-color: transparent;
}

.chat-widget-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(62, 39, 35, 0.3);
}

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

.chat-widget-btn.pulse {
    animation: cwPulse 2s ease-in-out infinite;
}

@keyframes cwPulse {
    0%, 100% { box-shadow: var(--cw-shadow-lg); }
    50% { box-shadow: 0 4px 24px rgba(139, 69, 19, 0.5), 0 0 0 16px rgba(212, 167, 106, 0.15); }
}

/* --- 聊天面板 --- */
.chat-widget-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 520px;
    min-width: 300px;
    min-height: 400px;
    max-width: 800px;
    max-height: 800px;
    background: var(--cw-white);
    border-radius: var(--cw-radius);
    box-shadow: var(--cw-shadow-lg);
    z-index: var(--cw-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid var(--cw-border);
}

.chat-widget-panel.collapsed {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.chat-widget-panel.minimized {
    height: auto !important;
    min-height: auto !important;
    max-height: 56px !important;
}

/* --- 面板头部 --- */
.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-light));
    color: #FFF;
    cursor: default;
    user-select: none;
    border-radius: var(--cw-radius) var(--cw-radius) 0 0;
}

.chat-widget-header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-widget-header-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.chat-widget-header-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.chat-widget-header-subtitle {
    font-size: 11px;
    opacity: 0.85;
}

.chat-widget-header-actions {
    display: flex;
    gap: 4px;
}

.chat-widget-header-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.18);
    color: #FFF;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

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

/* --- 消息区域 --- */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--cw-bg-light);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

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

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: var(--cw-accent-light);
    border-radius: 10px;
}

/* --- 消息气泡 --- */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: cwMsgIn 0.3s ease;
}

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

.chat-message.user {
    align-self: flex-end;
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.chat-message.user .chat-message-bubble {
    background: var(--cw-user-bubble);
    color: var(--cw-user-text);
    border-bottom-right-radius: 4px;
}

.chat-message.bot .chat-message-bubble {
    background: var(--cw-bot-bubble);
    color: var(--cw-bot-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--cw-border);
}

.chat-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-message.user .chat-message-time {
    align-self: flex-end;
}

.chat-message.bot .chat-message-time {
    align-self: flex-start;
}

/* --- 相关文章 --- */
.chat-related-articles {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--cw-accent-light);
    border-radius: var(--cw-radius-sm);
    font-size: 12px;
}

.chat-related-articles-title {
    font-weight: 600;
    color: var(--cw-primary);
    margin-bottom: 4px;
    font-size: 12px;
}

.chat-related-articles a {
    display: block;
    color: var(--cw-primary);
    text-decoration: none;
    padding: 2px 0;
    font-size: 12px;
    transition: color 0.2s;
}

.chat-related-articles a:hover {
    color: var(--cw-primary-light);
    text-decoration: underline;
}

/* --- 建议标签 --- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.chat-suggestion-chip {
    padding: 6px 14px;
    background: var(--cw-bg);
    border: 1px solid var(--cw-accent);
    color: var(--cw-primary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.chat-suggestion-chip:hover {
    background: var(--cw-accent);
    color: #FFF;
}

.chat-suggestion-chip:active {
    transform: scale(0.96);
}

/* --- 输入区 --- */
.chat-widget-input-area {
    padding: 10px 14px 8px;
    background: var(--cw-white);
    border-top: 1px solid var(--cw-border);
}

.chat-widget-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-widget-input {
    flex: 1;
    border: 1px solid var(--cw-border);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 80px;
    background: var(--cw-bg-light);
    color: var(--cw-text);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-widget-input:focus {
    border-color: var(--cw-accent);
    box-shadow: 0 0 0 3px rgba(212, 167, 106, 0.2);
}

.chat-widget-input::placeholder {
    color: #BCAAA4;
}

.chat-widget-send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cw-primary), var(--cw-primary-light));
    color: #FFF;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

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

.chat-widget-send-btn:active {
    transform: scale(0.9);
}

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

/* --- 打字指示器 --- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--cw-bot-bubble);
    border: 1px solid var(--cw-border);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: cwMsgIn 0.3s ease;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cw-accent);
    animation: cwTypingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes cwTypingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* --- 欢迎消息 --- */
.chat-welcome-msg {
    text-align: center;
    padding: 20px 10px;
    color: var(--cw-text-light);
    font-size: 14px;
    line-height: 1.6;
}

.chat-welcome-msg .welcome-icon {
    font-size: 42px;
    display: block;
    margin-bottom: 10px;
}

.chat-welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}

/* --- 调整大小手柄 --- */
.chat-widget-resize-handle {
    position: absolute;
    z-index: 2;
}

.chat-widget-resize-handle.top {
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    cursor: n-resize;
}

.chat-widget-resize-handle.left {
    top: 0;
    left: 0;
    bottom: 0;
    width: 5px;
    cursor: w-resize;
}

.chat-widget-resize-handle.corner {
    top: 0;
    left: 0;
    width: 12px;
    height: 12px;
    cursor: nw-resize;
}

/* --- 迷你化时隐藏调整手柄 --- */
.chat-widget-panel.minimized .chat-widget-resize-handle {
    display: none;
}

/* --- 移动端响应 --- */
@media (max-width: 768px) {
    .chat-widget-btn {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
        font-size: 24px;
    }

    .chat-widget-panel {
        width: calc(100vw - 32px) !important;
        height: calc(100vh - 120px) !important;
        max-width: 100vw !important;
        max-height: calc(100vh - 120px) !important;
        min-width: 280px !important;
        bottom: 80px;
        right: 16px;
        left: 16px;
    }

    .chat-widget-resize-handle {
        display: none;
    }

    .chat-message {
        max-width: 90%;
    }
}

/* --- 错误消息 --- */
.chat-error-msg {
    text-align: center;
    padding: 12px;
    margin: 8px 0;
    background: #FFF0F0;
    border: 1px solid #FFCDD2;
    border-radius: var(--cw-radius-sm);
    color: #C62828;
    font-size: 13px;
}

.chat-error-retry {
    color: var(--cw-primary);
    text-decoration: underline;
    cursor: pointer;
    margin-left: 4px;
}

/* --- 通知徽标 --- */
.chat-widget-btn .chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #F44336;
    color: #FFF;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #FFF;
    animation: cwBadgeIn 0.3s ease;
}

@keyframes cwBadgeIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* =============================================
   电话拨打引导 - 玻璃态浮动弹窗
   ============================================= */
.chat-phone-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    animation: phoneOverlayIn 0.3s ease;
}
.chat-phone-overlay.show {
    display: flex;
}
.chat-phone-overlay.auto-hide {
    animation: phoneOverlayOut 0.5s ease forwards;
}
@keyframes phoneOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes phoneOverlayOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.chat-phone-modal {
    position: relative;
    background: rgba(255,255,255,0.18);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    border-radius: 24px;
    padding: 40px 36px 32px;
    max-width: 360px;
    width: 88%;
    text-align: center;
    border: 1.5px solid rgba(255,255,255,0.3);
    box-shadow:
        0 8px 32px rgba(0,0,0,0.18),
        0 2px 8px rgba(0,0,0,0.06),
        inset 0 1px 0 rgba(255,255,255,0.4);
    animation: phoneModalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
}
@keyframes phoneModalPop {
    from { 
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to { 
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* 光泽流动 */
.chat-phone-shimmer {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(255,255,255,0.08) 40%,
        rgba(255,255,255,0.15) 50%,
        rgba(255,255,255,0.08) 60%,
        transparent 70%
    );
    animation: shimmerMove 3s ease-in-out infinite;
    pointer-events: none;
}
@keyframes shimmerMove {
    0% { transform: translate(-20%, -20%) rotate(0deg); }
    50% { transform: translate(10%, 10%) rotate(5deg); }
    100% { transform: translate(-20%, -20%) rotate(0deg); }
}

.chat-phone-icon {
    font-size: 52px;
    margin-bottom: 12px;
    animation: phoneBounce 0.6s ease infinite alternate;
    position: relative;
    z-index: 1;
}
@keyframes phoneBounce {
    from { transform: translateY(0); }
    to { transform: translateY(-6px); }
}

.chat-phone-title {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.chat-phone-desc {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    line-height: 1.6;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.chat-phone-number {
    display: block;
    font-size: 30px;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
    padding: 14px 24px;
    border-radius: 16px;
    background: rgba(255,255,255,0.15);
    border: 1.5px solid rgba(255,255,255,0.35);
    margin-bottom: 8px;
    letter-spacing: 2px;
    transition: all 0.2s ease;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.chat-phone-number:hover {
    background: rgba(255,255,255,0.25);
    border-color: rgba(255,255,255,0.6);
    transform: scale(1.03);
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.chat-phone-number:active {
    transform: scale(0.98);
}

.chat-phone-hint {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    margin-bottom: 18px;
    position: relative;
    z-index: 1;
}

.chat-phone-close {
    display: inline-block;
    padding: 10px 32px;
    border-radius: 100px;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    z-index: 1;
}
.chat-phone-close:hover {
    background: rgba(255,255,255,0.35);
}

/* =============================================
   待回复 / 已回复 状态徽章
   ============================================= */
.chat-pending-badge {
    font-size: 11px;
    color: #E65100;
    background: #FFF3E0;
    padding: 5px 10px;
    border-radius: 10px;
    margin-top: 4px;
    display: inline-block;
    animation: pendingPulse 1.5s ease infinite;
}
@keyframes pendingPulse {
    0%,100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.chat-admin-reply-badge {
    font-size: 11px;
    color: #2E7D32;
    background: #E8F5E9;
    padding: 5px 10px;
    border-radius: 10px;
    margin-top: 4px;
    display: inline-block;
}

/* tel 链接样式 */
.chat-tel-link {
    color: #D4A76A;
    font-weight: bold;
    text-decoration: underline;
}

/* 相关文章标签 */
.chat-related-tag {
    display: inline-block;
    background: #F5F0E8;
    color: #8B4513;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    margin: 2px;
}

/* 人工客服按钮 */
.chat-widget-actions-row {
    display: flex;
    justify-content: flex-end;
    padding: 4px 0 0;
}

.chat-widget-human-btn {
    background: none;
    border: 1px solid #E0D5C0;
    color: #8B4513;
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.chat-widget-human-btn:hover {
    background: #FFF8F0;
    border-color: #D4A76A;
    color: #6B3410;
}
.chat-widget-human-btn:active {
    transform: scale(0.96);
}
