/*
 * Copyright: YC-2025Copyright
 * Created: 2026-08-31
 * Description: 前台客服悬浮窗（微信/在线/电话咨询）
 */

/* ===== 主题变量：跟随系统 style.css 的 :root 主色，宿主未加载 style.css 时退回 fallback ===== */
:root {
    --fw-primary: var(--primary-color, #5B7CFF);
    --fw-primary-dark: var(--primary-dark, #4A6BE8);
    --fw-primary-soft: rgba(91, 124, 255, .10);
    --fw-primary-soft-strong: rgba(91, 124, 255, .18);
    --fw-primary-shadow: rgba(91, 124, 255, .14);
}

/* ===== 悬浮窗主体（官网设计稿：白色圆角卡片 + 黑色线条图标竖排，无文字标签） ===== */
#cg-float-widget {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9990;
    font-family: inherit;
}

.cg-fw-main {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(17, 24, 39, .12);
    overflow: hidden;
    width: 60px;
    padding: 6px 0;
}

.cg-fw-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 56px;
    padding: 0;
    background: #fff;
    border: 0;
    color: #1f2937;
    cursor: pointer;
    transition: background .2s;
}
/* 图标之间的内缩细分隔线 */
.cg-fw-item:not(:last-child)::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 0;
    height: 1px;
    background: #eef1f5;
}

.cg-fw-item:hover,
.cg-fw-item.is-active { background: #f5f8ff; }
.cg-fw-item i { font-size: 24px; color: #1f2937; }
.cg-fw-item-img {
    width: 26px;
    height: 26px;
    object-fit: contain;
}
/* 设计稿为纯图标样式，文字仅保留在 DOM 中供无障碍与悬停提示使用 */
.cg-fw-item span {
    display: none;
}

/* ===== 左侧弹层（二维码/电话） ===== */
.cg-fw-pop {
    position: absolute;
    right: 60px; /* 紧贴主窗，避免鼠标移动时出现 hover 断层 */
    bottom: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(17, 24, 39, .16);
    padding: 16px;
    display: none;
}

.cg-fw-pop.is-show { display: block; animation: cg-fw-fade .2s ease; }
.cg-fw-pop img {
    display: block;
    width: 150px;
    height: 150px;
    object-fit: contain;
    background: #f9fafb;
}
.cg-fw-pop .cg-fw-pop-tip {
    margin-top: 8px;
    text-align: center;
    font-size: 12px;
    color: #475467;
}
.cg-fw-pop .cg-fw-pop-empty {
    width: 150px;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f9fafb;
    color: #98a2b3;
    font-size: 13px;
    border-radius: 4px;
}
.cg-fw-pop .cg-fw-pop-phone {
    font-size: 22px;
    font-weight: 700;
    color: var(--fw-primary);
    text-decoration: none;
    white-space: nowrap;
}

@keyframes cg-fw-fade {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* 聊天窗垂直居中定位专用动画，避免覆盖 translateY(-50%) */
@keyframes cg-fw-fade-center {
    from { opacity: 0; transform: translateY(calc(-50% + 6px)); }
    to { opacity: 1; transform: translateY(-50%); }
}

/* ===== 聊天小窗 ===== */
.cg-fw-chat {
    position: fixed;
    right: 120px;
    top: 50%;
    transform: translateY(-50%);
    width: 360px;
    height: 520px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(17, 24, 39, .22);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 9991;
}

.cg-fw-chat.is-show { display: flex; animation: cg-fw-fade-center .2s ease; }

.cg-fw-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(90deg, var(--fw-primary), var(--fw-primary-dark));
    color: #fff;
}

.cg-fw-chat-head .cg-fw-chat-title { font-weight: 600; font-size: 14px; }
.cg-fw-head-actions { display: flex; align-items: center; gap: 6px; }
.cg-fw-head-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, .18);
    border: 0;
    border-radius: 20px;
    color: #fff;
    font-size: 12px;
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
    transition: background .2s;
}
.cg-fw-head-btn:hover { background: rgba(255, 255, 255, .32); }
.cg-fw-chat-close {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.cg-fw-chat-body { flex: 1; overflow-y: auto; padding: 16px 12px; background: #f5f7fb; }

.cg-fw-msg { display: flex; gap: 8px; margin-bottom: 14px; }
.cg-fw-msg-user { flex-direction: row-reverse; }
.cg-fw-msg i {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--fw-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}
.cg-fw-msg-user i { background: #98a2b3; }

.cg-fw-msg-bubble {
    max-width: 76%;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 1px 4px rgba(17, 24, 39, .08);
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}
.cg-fw-msg-user .cg-fw-msg-bubble { background: var(--fw-primary); color: #fff; }

.cg-fw-typing span {
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-right: 3px;
    border-radius: 50%;
    background: #98a2b3;
    animation: cg-fw-blink 1.2s infinite;
}
.cg-fw-typing span:nth-child(2) { animation-delay: .2s; }
.cg-fw-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes cg-fw-blink {
    0%, 80%, 100% { opacity: .3; }
    40% { opacity: 1; }
}

.cg-fw-chat-foot { border-top: 1px solid #eef1f5; padding: 10px 12px; background: #fff; }
.cg-fw-chat-input {
    width: 100%;
    height: 56px;
    resize: none;
    border: 1px solid #e4e7ec;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
}
.cg-fw-chat-input:focus { border-color: var(--fw-primary); }
.cg-fw-chat-send-row { display: flex; justify-content: flex-end; margin-top: 8px; }
.cg-fw-chat-send {
    background: var(--fw-primary);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 6px 18px;
    font-size: 13px;
    cursor: pointer;
}
.cg-fw-chat-send:disabled { opacity: .6; cursor: not-allowed; }
.cg-fw-chat-foot .cg-fw-hint { font-size: 11px; color: #98a2b3; }

/* 空会话提示 */
.cg-fw-empty {
    height: 100%;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #98a2b3;
    font-size: 13px;
}
.cg-fw-empty i { font-size: 32px; opacity: .6; }

/* ===== 欢迎区（新建会话状态） ===== */
.cg-fw-welcome { padding: 8px 2px 4px; }
.cg-fw-welcome-avatar {
    width: 64px;
    height: 64px;
    margin: 8px auto 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--fw-primary-soft), var(--fw-primary-soft-strong));
    display: flex;
    align-items: center;
    justify-content: center;
}
.cg-fw-welcome-avatar i { font-size: 30px; color: var(--fw-primary); }
.cg-fw-welcome-title {
    margin: 0 0 8px;
    text-align: center;
    font-size: 17px;
    font-weight: 700;
    color: #101828;
}
.cg-fw-welcome-desc {
    margin: 0 auto 18px;
    text-align: center;
    font-size: 12px;
    line-height: 1.7;
    color: #667085;
    padding: 0 6px;
}
.cg-fw-quick-label {
    font-size: 12px;
    color: #98a2b3;
    margin-bottom: 8px;
}
.cg-fw-quick { display: flex; flex-direction: column; gap: 8px; }
.cg-fw-quick-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 1px solid #eef1f5;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12px;
    color: #475467;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s;
}
.cg-fw-quick-btn:hover { border-color: var(--fw-primary); box-shadow: 0 4px 14px var(--fw-primary-shadow); }
.cg-fw-quick-btn i {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--fw-primary-soft);
    color: var(--fw-primary);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cg-fw-quick-btn strong {
    display: block;
    font-size: 13px;
    color: #101828;
    margin-bottom: 2px;
}

/* ===== 历史会话下拉 ===== */
.cg-fw-sessions {
    position: absolute;
    top: 46px;
    left: 10px;
    right: 10px;
    max-height: 320px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #eef1f5;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(17, 24, 39, .18);
    padding: 8px;
    z-index: 5;
}
.cg-fw-sessions-loading,
.cg-fw-sessions-empty {
    padding: 18px 0;
    text-align: center;
    color: #98a2b3;
    font-size: 13px;
}
.cg-fw-session-item {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
}
.cg-fw-session-item:hover { background: var(--fw-primary-soft); }
.cg-fw-session-item .cg-fw-session-title {
    font-size: 13px;
    color: #344054;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cg-fw-session-item .cg-fw-session-meta {
    margin-top: 2px;
    font-size: 11px;
    color: #98a2b3;
}

/* ===== 响应式（H5） ===== */
@media (max-width: 767.98px) {
    #cg-float-widget { right: 10px; top: 50%; }
    .cg-fw-head-btn { font-size: 0; gap: 0; padding: 4px 8px; }
    .cg-fw-head-btn i { font-size: 13px; }
    .cg-fw-chat {
        right: 8px;
        top: 50%;
        width: calc(100vw - 16px);
        height: 70vh;
    }
    .cg-fw-pop { right: 60px; }
}

@media (prefers-reduced-motion: reduce) {
    .cg-fw-pop.is-show,
    .cg-fw-chat.is-show { animation: none; }
}
