/* ============================================================================
   价值页 · 匿名咨询（chat）— 浮窗样式
   与站点保持同一套配色：暖白纸面 + 琥珀强调色
   ========================================================================== */

.chat-widget {
    --cw-accent: var(--accent, #B45309);
    --cw-paper: var(--paper, #fffef9);
    --cw-border: var(--border-light, #e5e0d4);
    --cw-text: var(--text, #1f1f1f);
    --cw-muted: var(--text-muted, #9a9a9a);
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9999;
    font-family: var(--font-body, -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif);
}

/* ---------- 悬浮按钮 ---------- */
.chat-toggle {
    width: 52px;
    height: 52px;
    border: 0;
    border-radius: 50%;
    background: var(--cw-accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    position: relative;
    transition: transform .18s ease, box-shadow .18s ease;
}
.chat-toggle:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, .24); }
.chat-toggle:active { transform: scale(.96); }
.chat-toggle svg { width: 24px; height: 24px; }

/* 有管理员回复时：整个按钮呼吸式发光，红点闪烁并显示条数 */
.chat-toggle.has-unread {
    animation: chat-pulse 1.5s ease-in-out infinite;
}
.chat-dot {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #DC2626;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    border: 2px solid var(--cw-paper);
    box-sizing: content-box;
    animation: chat-blink 1s steps(2, start) infinite;
}
.chat-dot[hidden] { display: none; }

@keyframes chat-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: .35; }
}
@keyframes chat-pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, .18), 0 0 0 0 rgba(220, 38, 38, .55); }
    70%      { box-shadow: 0 4px 16px rgba(0, 0, 0, .18), 0 0 0 12px rgba(220, 38, 38, 0); }
}

/* ---------- 面板 ---------- */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: 66px;
    width: 340px;
    height: 480px;
    max-height: calc(100vh - 100px);
    background: var(--cw-paper);
    border: 1px solid var(--cw-border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--cw-border);
    background: var(--cw-paper);
    flex: 0 0 auto;
}
.chat-head strong { font-size: 15px; color: var(--cw-text); }
.chat-timer {
    margin-left: 8px;
    font-size: 12px;
    color: var(--cw-muted);
    font-variant-numeric: tabular-nums;
}
.chat-timer.urgent { color: #DC2626; }
.chat-close {
    border: 0;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    color: var(--cw-muted);
    cursor: pointer;
    padding: 0 4px;
}
.chat-close:hover { color: var(--cw-text); }

.chat-tip {
    flex: 0 0 auto;
    padding: 8px 14px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--cw-muted);
    background: #f7f5ef;
    border-bottom: 1px solid var(--cw-border);
}

/* ---------- 消息区 ---------- */
.chat-log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}
.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--cw-muted);
    font-size: 13px;
    line-height: 1.8;
}

.msg { display: flex; }
.msg.me { justify-content: flex-end; }

.msg-bubble {
    max-width: 82%;
    padding: 8px 11px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}
.msg.peer .msg-bubble {
    background: #f2f1ec;
    color: var(--cw-text);
    border-bottom-left-radius: 3px;
}
.msg.me .msg-bubble {
    background: var(--cw-accent);
    color: #fff;
    border-bottom-right-radius: 3px;
}
.msg-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.msg.me .msg-bubble a { color: #fff; }

.msg-bubble img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 6px;
    cursor: zoom-in;
}

/* 图片放大查看 */
.chat-zoom {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: zoom-out;
    padding: 16px;
}
.chat-zoom img { max-width: 100%; max-height: 100%; border-radius: 4px; }
.chat-zoom[hidden] { display: none; }

/* ---------- 底部操作 ---------- */
.chat-actions {
    flex: 0 0 auto;
    padding: 0 14px 6px;
}
.chat-link {
    border: 0;
    background: transparent;
    color: var(--cw-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.chat-link:hover { color: #DC2626; }

.chat-form {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px 10px;
    border-top: 1px solid var(--cw-border);
    background: var(--cw-paper);
}
.chat-input {
    flex: 1 1 auto;
    min-height: 38px;
    max-height: 96px;
    resize: none;
    border: 1px solid var(--cw-border);
    border-radius: 8px;
    padding: 9px 10px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    color: var(--cw-text);
    background: #fff;
    outline: none;
}
.chat-input:focus { border-color: var(--cw-accent); }

.chat-attach {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cw-border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    color: var(--cw-muted);
    background: #fff;
}
.chat-attach:hover { color: var(--cw-accent); border-color: var(--cw-accent); }

.chat-send {
    flex: 0 0 auto;
    height: 38px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    background: var(--cw-accent);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}
.chat-send:disabled { opacity: .5; cursor: default; }

/* ---------- 手机端：全屏 ---------- */
@media (max-width: 768px) {
    .chat-widget { right: 14px; bottom: 14px; }
    .chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: 0;
        bottom: 0;
        right: 0;
    }
    .chat-panel .chat-log { padding: 12px; }
    .chat-input { font-size: 16px; } /* 防止 iOS 聚焦时自动放大页面 */
    .chat-toggle { width: 48px; height: 48px; }
}

/* ---------- 页脚「定制研究可chat」入口 ---------- */
.footer-chat-link {
    color: var(--cw-accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
.footer-chat-link:hover { opacity: .75; }
