/* ============================================================
   慧惠 AI 聊天组件 — 完整样式
   配色：水墨道风 — 墨绿 #2e5f5f / 淡金 #d4c9a8 / 宣纸 #faf8f0
   ============================================================ */

/* ----- CSS 变量 ----- */
:root {
    --hui-text: #2b3b3b;
    --hui-text-light: #6a7a7a;
    --hui-bg: #faf8f0;
    --hui-bg-secondary: #f0ede0;
    --hui-accent: #2e5f5f;
    --hui-accent-hover: #1d4a4a;
    --hui-border: #d4c9a8;
    --hui-gold: #d4af37;
    --hui-ai-bg: #f0ede0;
    --hui-user-bg: #e8f0ee;
    --hui-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --hui-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --hui-radius: 10px;
    --hui-radius-sm: 6px;
    --hui-font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    --btn-size: 50px;
    --panel-width: 380px;
    --panel-height: 520px;
}

/* ----- 浮动按钮 ----- */
#huihui-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    width: var(--btn-size);
    height: var(--btn-size);
    border-radius: 50%;
    background: linear-gradient(135deg, #2e5f5f 0%, #3a7a6a 100%);
    border: 1px solid rgba(212, 175, 55, 0.3);
    box-shadow: var(--hui-shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#huihui-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(46, 95, 95, 0.20);
}

#huihui-chat-btn:active {
    transform: scale(0.95);
}

#huihui-chat-btn svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: #faf8f0;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* 按钮脉冲提示（首次加载 3 秒后消失） */
#huihui-chat-btn.pulse::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(46, 95, 95, 0.2);
    animation: hui-pulse 2s ease-out infinite;
}

@keyframes hui-pulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }

    100% {
        transform: scale(1.3);
        opacity: 0;
    }
}

/* ----- 聊天面板 ----- */
#huihui-chat-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 9999;
    width: var(--panel-width);
    height: var(--panel-height);
    max-height: calc(100vh - 120px);
    background: var(--hui-bg);
    border: 1px solid var(--hui-border);
    border-radius: var(--hui-radius);
    box-shadow: var(--hui-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--hui-font);
}

#huihui-chat-panel.open {
    display: flex;
}

/* ----- 面板头部 ----- */
.hui-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #2e5f5f 0%, #3a7a6a 100%);
    color: #faf8f0;
    flex-shrink: 0;
}

.hui-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hui-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(250, 248, 240, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1em;
}

.hui-header-title {
    font-size: 0.95em;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.hui-header-subtitle {
    font-size: 0.72em;
    opacity: 0.7;
    font-weight: 400;
}

.hui-close-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(250, 248, 240, 0.15);
    color: #faf8f0;
    cursor: pointer;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.hui-close-btn:hover {
    background: rgba(250, 248, 240, 0.30);
}

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

.hui-messages::-webkit-scrollbar {
    width: 4px;
}

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

.hui-messages::-webkit-scrollbar-thumb {
    background: var(--hui-border);
    border-radius: 2px;
}

/* ----- 消息气泡 ----- */
.hui-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: hui-fade-in 0.25s ease-out;
}

@keyframes hui-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hui-msg.ai {
    align-self: flex-start;
}

.hui-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.hui-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75em;
    margin-top: 2px;
}

.hui-msg.ai .hui-msg-avatar {
    background: rgba(46, 95, 95, 0.12);
}

.hui-msg.user .hui-msg-avatar {
    background: rgba(212, 175, 55, 0.15);
}

.hui-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--hui-radius-sm);
    font-size: 0.88em;
    line-height: 1.7;
    color: var(--hui-text);
    word-break: break-word;
}

.hui-msg.ai .hui-msg-bubble {
    background: var(--hui-ai-bg);
    border: 1px solid rgba(212, 201, 168, 0.4);
    border-top-left-radius: 2px;
}

.hui-msg.user .hui-msg-bubble {
    background: var(--hui-user-bg);
    border: 1px solid rgba(46, 95, 95, 0.12);
    border-top-right-radius: 2px;
}

/* 打字指示器 */
.hui-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.hui-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--hui-border);
    animation: hui-bounce 1.4s ease-in-out infinite both;
}

.hui-typing span:nth-child(1) {
    animation-delay: 0s;
}

.hui-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.hui-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes hui-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ----- 输入区域 ----- */
.hui-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--hui-border);
    background: var(--hui-bg);
    flex-shrink: 0;
}

.hui-input {
    flex: 1;
    border: 1px solid var(--hui-border);
    border-radius: var(--hui-radius-sm);
    padding: 8px 12px;
    font-size: 0.88em;
    font-family: var(--hui-font);
    line-height: 1.5;
    color: var(--hui-text);
    background: #fffef5;
    resize: none;
    outline: none;
    max-height: 100px;
    min-height: 36px;
    transition: border-color 0.2s;
}

.hui-input:focus {
    border-color: var(--hui-accent);
}

.hui-input::placeholder {
    color: #b5aa8f;
}

.hui-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--hui-accent);
    color: #faf8f0;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    font-size: 0.9em;
}

.hui-send-btn:hover {
    background: var(--hui-accent-hover);
}

.hui-send-btn:active {
    transform: scale(0.92);
}

.hui-send-btn:disabled {
    background: #b5aa8f;
    cursor: not-allowed;
}

/* ----- 错误提示 ----- */
.hui-error {
    background: #fdf2f2;
    border: 1px solid #e8c8c8;
    color: #8a4a4a;
    padding: 8px 12px;
    border-radius: var(--hui-radius-sm);
    font-size: 0.82em;
    text-align: center;
    margin: 4px 0;
}

/* ============================================================
   移动端响应式适配
   ============================================================ */
@media (max-width: 480px) {
    #huihui-chat-btn {
        bottom: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
    }

    #huihui-chat-btn svg {
        width: 20px;
        height: 20px;
    }

    #huihui-chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }

    #huihui-chat-panel.open {
        /* 全屏模式下隐藏背景滚动（通过 JS 控制 body overflow） */
    }

    .hui-header {
        padding: 14px 16px;
        /* 为 iPhone 刘海留安全区 */
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .hui-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* 小屏手机 (宽度 ≤ 360px) */
@media (max-width: 360px) {
    .hui-msg {
        max-width: 92%;
    }

    .hui-msg-bubble {
        font-size: 0.84em;
        padding: 8px 12px;
    }
}

/* ============================================================
   认知水平分层按钮栏
   ============================================================ */
.huihui-level-bar {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: #faf8f0;
    border-bottom: 1px solid #d4c9a8;
    flex-shrink: 0;
    justify-content: center;
}

.huihui-level-btn {
    padding: 4px 12px;
    border-radius: 14px;
    border: 1px solid #2e5f5f;
    background: #f0ede0;
    color: #2e5f5f;
    font-size: 12px;
    font-family: var(--hui-font);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.huihui-level-btn:hover {
    background: #e0dcc8;
}

.huihui-level-btn.active {
    background: #2e5f5f;
    color: #fff;
}

@media (max-width: 480px) {
    .huihui-level-bar {
        flex-wrap: wrap;
        padding: 6px 8px;
    }

    .huihui-level-btn {
        font-size: 11px;
        padding: 3px 8px;
    }
}