/* ============================================================================
   AI 客服「小威」—— 右下角形象 + 对话窗口
   （consult/widget.php 输出结构，consult/assets 下两张形象图）

   · 形象是**静态两张图硬切**：平时 work 图，悬停/激活切 wave 图，没有动画。
   · 面板与形象同一位置：打开面板时形象隐藏，关掉再回来。
   · 类名一律 cw- 前缀（chat widget），不与站点其他样式撞。
   ============================================================================ */

.cw {
    /* 形象尺寸：2026-11-11 用户要求「整体缩小 30%」→ 250 / 230 等比缩到 175 / 161。
       舞台高度按 3:4 由 --cw-w 算出，两张形象图 width:100% 跟着缩，改这一个值就整体缩放。 */
    --cw-w: 175px;
    --cw-bubble-w: 161px;
    /* 2026-11-11 用户「形象整体上移一个身位」：身位 ≈ 0.8 × 宽度（别写死像素，跟着 --cw-w 走） */
    --cw-raise: calc(var(--cw-w) * .8);
    --cw-accent: #f97316;
    --cw-ink: #1f2733;
    --cw-line: #e6e8ec;

    position: fixed;
    right: 32px;
    bottom: calc(24px + var(--cw-raise));
    z-index: 1300;
    width: var(--cw-w);
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    user-select: none;
}

.cw[hidden] {
    display: none;
}

/* 欢迎气泡
   ⚠️ 贴头顶、别按"容器顶部"算：形象图是 3:4 的透明画布，上部还有 27% 的留白，
   头顶（中央带第一个有内容的行）在画布 29.5% 处 → 换算到容器就是离顶约 23%。
   `bottom` 的百分比按容器高度算，所以 `bottom: 77%` = 气泡底边离容器顶 23%，正好压到头顶上方几像素。 */
.cw-bubble {
    position: absolute;
    left: 50%;
    bottom: 77%;
    transform: translateX(-50%);
    width: var(--cw-bubble-w);
    padding: 12px 16px;
    background: #fff;
    border: 1px solid var(--cw-line);
    border-radius: 14px;
    color: var(--cw-ink);
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 10px 30px rgba(20, 28, 40, .12);
    opacity: 0;
    visibility: hidden;
}

.cw-bubble::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -6px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-right: 1px solid var(--cw-line);
    border-bottom: 1px solid var(--cw-line);
    transform: translateX(-50%) rotate(45deg);
}

.cw-bubble b {
    color: var(--cw-accent);
}

/* 形象舞台：3:4 画布，两张图叠放 */
.cw-stage {
    position: relative;
    display: block;
    width: 100%;
    height: calc(var(--cw-w) * 4 / 3);
    padding: 0;
    border: 0;
    background: none;
    overflow: hidden;
    cursor: pointer;
}

.cw-stage img {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    display: block;
    pointer-events: none;
}

.cw-img-wave {
    opacity: 0;
}

.cw:hover .cw-img-work,
.cw.is-active .cw-img-work,
.cw-stage:focus-visible .cw-img-work {
    opacity: 0;
}

.cw:hover .cw-img-wave,
.cw.is-active .cw-img-wave,
.cw-stage:focus-visible .cw-img-wave {
    opacity: 1;
}

.cw:hover .cw-bubble,
.cw.is-active .cw-bubble,
.cw-stage:focus-visible ~ .cw-bubble {
    opacity: 1;
    visibility: visible;
}

/* ------------------------------------------------------------
   对话面板
   ------------------------------------------------------------ */
.cw-panel {
    position: fixed;
    right: 32px;
    bottom: 24px;
    z-index: 1310;
    display: flex;
    flex-direction: column;
    width: 384px;
    max-width: calc(100vw - 32px);
    height: 582px;
    max-height: calc(100vh - 48px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 60px rgba(18, 26, 40, .24);
    overflow: hidden;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--cw-ink, #1f2733);
}

.cw-panel[hidden] {
    display: none;
}

/* 头部 */
.cw-panel__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #224b97, #2f62bd);
    color: #fff;
    flex: none;
}

.cw-panel__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    overflow: hidden;
    flex: none;
}

.cw-panel__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 12%;
    display: block;
}

.cw-panel__title {
    flex: 1;
    min-width: 0;
}

.cw-panel__title strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
}

.cw-panel__title small {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: rgba(255, 255, 255, .82);
}

.cw-panel__close {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.cw-panel__close:hover {
    background: rgba(255, 255, 255, .28);
}

/* 消息区 */
.cw-panel__body {
    flex: 1;
    padding: 16px 14px 8px;
    overflow-y: auto;
    /* 纯白：气泡靠边框 + 轻微阴影浮起来，不再靠底色反差 */
    background: #fff;
    scroll-behavior: smooth;
}

.cw-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
}

.cw-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex: none;
    overflow: hidden;
    background: #e9edf3;
}

.cw-msg__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 12%;
    display: block;
}

.cw-msg__bubble {
    max-width: 258px;
    padding: 10px 13px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e9ecf1;
    /* 轻微阴影：别加重，重了像卡片 */
    box-shadow: 0 1px 2px rgba(28, 39, 58, .06);
    font-size: 14px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: hidden; /* 让底部的跳转条被圆角裁住 */
}

.cw-msg__bubble a {
    color: #224b97;
    text-decoration: underline;
    word-break: break-all;
}

/* 气泡底部的跳转条：分隔线 + 居中蓝字
   AI 想引导客户去某个页面时，回复末尾的 [页面名](/路径) 会被抽到这里（见 consult.js::renderBubble），
   不再把网址原文吐在正文里折行。 */
.cw-msg__links {
    margin: 9px -13px -10px;
    padding: 8px 13px 10px;
    border-top: 1px solid #edf0f5;
    text-align: center;
}

.cw-msg__links a {
    display: inline-block;
    color: #1a5bd6;
    font-size: 15px;
    line-height: 1.5;
    text-decoration: none;
    word-break: keep-all;
}

.cw-msg__links a:hover {
    text-decoration: underline;
}

/* 访客：右侧、主色底 */
.cw-msg--visitor {
    flex-direction: row-reverse;
}

.cw-msg--visitor .cw-msg__bubble {
    background: #224b97;
    border-color: #224b97;
    color: #fff;
}

.cw-msg--visitor .cw-msg__avatar {
    display: none;
}

/* 人工客服：左侧、浅橙底，一眼能看出换人了 */
.cw-msg--agent .cw-msg__bubble {
    background: #fff5ec;
    border-color: #fbd8b6;
}

.cw-msg--agent .cw-msg__avatar {
    background: #f97316;
    color: #fff;
    font-size: 12px;
    line-height: 28px;
    text-align: center;
}

/* 系统提示：居中灰字 */
.cw-msg--system {
    justify-content: center;
    margin: 10px 0;
}

.cw-msg--system .cw-msg__bubble {
    background: #eef1f5;
    border: 0;
    box-shadow: none;
    color: #7b8593;
    font-size: 12px;
    padding: 6px 12px;
    text-align: center;
}

/* 正在输入 */
.cw-typing {
    padding: 0 16px 8px;
    background: #fff;
    color: #8b95a3;
    font-size: 12px;
}

.cw-typing[hidden] {
    display: none;
}

/* 输入区 */
.cw-panel__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #eceff3;
    background: #fff;
    flex: none;
}

.cw-panel__input {
    flex: 1;
    min-height: 38px;
    max-height: 96px;
    padding: 9px 12px;
    border: 1px solid #dfe3e9;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    font-family: inherit;
    color: #1f2733;
    resize: none;
    outline: none;
}

.cw-panel__input:focus {
    border-color: #224b97;
}

.cw-panel__send {
    flex: none;
    height: 38px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: #224b97;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

.cw-panel__send:disabled {
    background: #b8c2d3;
    cursor: not-allowed;
}

/* 底部：免责说明（前台不设转人工入口） */
.cw-panel__foot {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px 10px;
    background: #fff;
    color: #98a1ad;
    font-size: 12px;
    flex: none;
}

/* 窄屏 */
@media (max-width: 767px) {
    .cw {
        /* 窄屏同样按 30% 收：184 / 190 → 129 / 133；上移量跟着 --cw-w 自动变小（129 × .8 ≈ 103） */
        --cw-w: 129px;
        --cw-bubble-w: 133px;
        right: 14px;
        bottom: calc(14px + var(--cw-raise));
    }

    .cw-panel {
        right: 8px;
        bottom: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: calc(100vh - 16px);
        max-height: none;
        border-radius: 14px;
    }

    .cw-msg__bubble {
        max-width: 76%;
    }
}
