/**
 * 吾侪AI助手 - 短代码内嵌专用样式
 * 与 chat-float.css 完全独立，互不干扰
 */

:root {
    --wucha-theme: #2271b1;
    --wucha-theme-dark: #135e96;
    --wucha-theme-light: #eaf2f8;
    --wucha-bg: #f7f8fa;
    --wucha-text: #333;
    --wucha-text-muted: #888;
    --wucha-border: #e1e4e8;
}

.wucha-theme-green  { --wucha-theme:#2ea44f; --wucha-theme-dark:#218838; --wucha-theme-light:#eaf7ec; }
.wucha-theme-orange { --wucha-theme:#e67e22; --wucha-theme-dark:#d35400; --wucha-theme-light:#fef5ea; }
.wucha-theme-purple { --wucha-theme:#8e44ad; --wucha-theme-dark:#6c3483; --wucha-theme-light:#f5eef8; }
.wucha-theme-dark   { --wucha-theme:#2c3e50; --wucha-theme-dark:#1a252f; --wucha-theme-light:#eaecee; }

/* ========== 基础容器 ==========
 * position: relative 是关键！
 * 和悬浮窗的 position: fixed 一样建立独立包含块
 * 让 height: 75vh 不再受页面流 / WP主题 影响
 */
.wucha-chat-inline {
    position: relative !important;
    width: 100% !important;
    min-height: 600px !important;
    height: 75vh !important;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.10);
    display: flex !important;
    flex-direction: row !important;
    overflow: hidden !important;
    font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
    border: 1px solid #eef0f3;
    margin: 20px 0;
}

/* ========== 全屏覆盖模式 ========== */
.wucha-chat-inline.wucha-inline-fullscreen {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    width: 100vw !important; height: 100vh !important;
    margin: 0 !important; border-radius: 0 !important; border: none !important;
    box-shadow: none !important; z-index: 99999 !important;
    overflow: hidden !important;
}
/* ✅ 登录状态下避开 admin bar，不覆盖顶部菜单栏 */
.wucha-chat-inline.wucha-inline-fullscreen.wucha-has-adminbar { top: 32px !important; height: calc(100vh - 32px) !important; }
@media screen and (max-width: 782px) {
    .wucha-chat-inline.wucha-inline-fullscreen.wucha-has-adminbar { top: 46px !important; height: calc(100vh - 46px) !important; }
}
html.wucha-fullscreen-open, html.wucha-fullscreen-open body { overflow: hidden !important; height: 100% !important; }

/* ========== 左侧侧边栏 ========== */
.wucha-chat-sidebar {
    width: 240px;
    flex-shrink: 0 !important;
    background: #f9fafb;
    border-right: 1px solid #eef0f3;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    min-height: 0 !important;
    height: 100% !important;
}
.wucha-sidebar-header { padding: 16px; border-bottom: 1px solid #eef0f3; display: flex; align-items: center; gap: 10px; }
.wucha-sidebar-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--wucha-theme), var(--wucha-theme-dark)); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; flex-shrink: 0; }
.wucha-sidebar-title { font-weight: 600; font-size: 15px; color: var(--wucha-text); }
.wucha-sidebar-newchat { margin: 12px; padding: 10px 14px; background: var(--wucha-theme); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; transition: background .2s; font-family: inherit; }
.wucha-sidebar-newchat:hover { background: var(--wucha-theme-dark); }
.wucha-sidebar-history {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 4px 8px;
}
.wucha-history-item { padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; color: #555; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s; position: relative; font-family: inherit; border: none; background: none; width: 100%; text-align: left; }
.wucha-history-item:hover { background: #eef0f3; color: var(--wucha-text); }
.wucha-history-item.active { background: var(--wucha-theme-light); color: var(--wucha-theme-dark); }
.wucha-history-item .del { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); opacity: 0; font-size: 16px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.wucha-history-item:hover .del { opacity: .5; }
.wucha-history-item .del:hover { opacity: 1; background: #fee; color: #e74c3c; }
.wucha-history-empty { text-align: center; color: #bbb; font-size: 13px; padding: 40px 10px; }

/* ========== 右侧主区域 ==========
 * 和悬浮窗的 .wucha-chat-window 完全相同：
 * flex-direction: column + overflow: hidden
 */
.wucha-chat-main {
    flex: 1 1 0 !important;
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: hidden !important;
    position: relative !important;
}

/* header — 和悬浮窗一样：flex-shrink:0 不被压缩 */
.wucha-chat-main-header {
    flex-shrink: 0 !important;
    padding: 16px 24px;
    border-bottom: 1px solid #eef0f3;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
}
.wucha-chat-main-header-title { font-size: 16px; font-weight: 600; color: var(--wucha-text); }
.wucha-chat-main-header-badge { font-size: 11px; color: #2ea44f; background: #eaf7ec; padding: 2px 10px; border-radius: 10px; }
.wucha-chat-main-header-actions { margin-left: auto; display: flex; gap: 6px; }
.wucha-chat-main-header-actions button {
    width: 32px !important; height: 32px !important; border: none !important; background: transparent !important; cursor: pointer !important;
    border-radius: 6px !important; font-size: 18px !important; line-height: 1 !important; color: #888 !important;
    transition: all .15s; font-family: inherit !important; pointer-events: auto !important; z-index: 10 !important; position: relative !important;
}
.wucha-chat-main-header-actions button:hover { background: #f0f1f3; color: #333; }
.wucha-chat-main-header-actions .wucha-inline-close:hover { background: #fee; color: #e74c3c; }

/* 消息体 — 和悬浮窗的 .wucha-chat-body 完全一样！
 * flex:1 + min-height:0 + overflow-y:auto = 一定能滚
 * 前提：父容器链都有确定高度（根容器 position:relative 已保证）
 */
.wucha-chat-main-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 24px 32px 32px;
    background: #fafbfc;
    display: flex !important;
    flex-direction: column !important;
    gap: 18px;
}

/* 🆕 快捷问题推荐：跟 AI 气泡/输入框一样 max-width + 居中 */
.wucha-chat-main-body > .wucha-suggestions {
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}

/* 输入区 — 和悬浮窗一样：flex-shrink:0 不被压缩 */
.wucha-chat-main-input {
    flex-shrink: 0 !important;
    padding: 14px 24px 22px;
    background: #fff;
    border-top: 1px solid #f0f1f3;
    box-shadow: 0 -2px 12px rgba(0,0,0,.04);
    position: relative;
    z-index: 2;
}
.wucha-main-input-box {
    max-width: 900px; margin: 0 auto;
    background: #f7f8fa; border: 1.5px solid #e4e6ea; border-radius: 24px;
    padding: 10px 14px 6px 22px;
    display: flex; flex-direction: column; gap: 2px;
    transition: border-color .25s, box-shadow .25s, background .25s;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.wucha-main-input-box:focus-within { background: #fff; border-color: var(--wucha-theme); box-shadow: 0 0 0 3px var(--wucha-theme-light), 0 2px 8px rgba(0,0,0,.06); }

/* 第一行：textarea + 发送按钮 */
.wucha-input-row-main {
    display: flex; align-items: center; gap: 8px;
}
.wucha-main-input-box textarea {
    flex: 1; border: none; outline: none; resize: none;
    font-size: 15px; line-height: 1.6;
    min-height: 24px; max-height: 180px; padding: 4px 0;
    font-family: inherit; background: transparent; color: var(--wucha-text);
}

/* 第二行：底部工具条 */
.wucha-input-row-tools {
    display: flex; align-items: center; justify-content: space-between;
    padding: 2px 0 4px;
    font-size: 11px;
}
.wucha-input-row-tools .wucha-tools-left {
    display: flex; align-items: center; gap: 4px; color: #888;
}
.wucha-input-row-tools .wucha-tools-right {
    display: flex; align-items: center; gap: 4px;
}
.wucha-input-row-tools .wucha-tools-web-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    cursor: pointer; color: #888; user-select: none;
}
.wucha-input-row-tools .wucha-tools-web-toggle input[type="checkbox"] {
    accent-color: #2271b1; margin: 0;
}
.wucha-input-row-tools .wucha-kb-list-btn,
.wucha-input-row-tools .wucha-kb-add-btn {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 8px; border-radius: 10px;
    font-size: 11px; cursor: pointer; font-family: inherit; line-height: 1.4;
    border: 1px solid;
}
.wucha-input-row-tools .wucha-kb-list-btn { border-color: #91caff; background: #e6f4ff; color: #0958d9; }
.wucha-input-row-tools .wucha-kb-add-btn  { border-color: #ffe58f; background: #fffbe6; color: #8c6d1f; }

/* 主发送按钮 */
.wucha-main-input-send {
    width: 38px !important; height: 38px !important; min-width: 38px !important; max-width: 38px !important;
    padding: 0 !important; background: transparent !important; color: var(--wucha-theme) !important;
    border: none !important; border-radius: 0 !important; cursor: pointer !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
    flex-shrink: 0 !important; font-size: 0 !important;
    transition: background .15s, transform .15s, color .15s !important;
}
.wucha-main-input-send svg { display: block; }
.wucha-main-input-send:hover:not(:disabled) { background: rgba(0,0,0,.06) !important; transform: scale(1.1); }
.wucha-main-input-send:active:not(:disabled) { transform: scale(.92); }
.wucha-main-input-send:disabled { background: transparent !important; color: #c8ccd0 !important; cursor: not-allowed !important; }

/* ========== 消息气泡（简约百度风） ========== */
.wucha-msg-wrap { display: flex; gap: 10px; align-items: flex-start; flex-shrink: 0 !important; margin-bottom: 14px; width: 100%; }
.wucha-msg-wrap.is-user { justify-content: flex-end; flex-direction: row-reverse; }
.wucha-msg-wrap.is-bot  { justify-content: flex-start; }
.wucha-msg-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; overflow: hidden; background: #e8eaed; }
.wucha-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
/* box：inline-flex + width:fit-content，align-items:flex-start 让昵称/气泡各自保持自身宽度 */
.wucha-msg-wrap > div:not(.wucha-msg-avatar) {
    display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px;
    width: fit-content; max-width: 900px; flex-shrink: 0 !important; min-width: 0;
}
.wucha-chat-main-body .wucha-msg {
    width: fit-content; max-width: 100%;
    padding: 10px 14px; border-radius: 8px; font-size: 14px; line-height: 1.7;
    box-sizing: border-box;
    background: #fff; color: #1a1a1a; border: 1px solid #eee;
    white-space: normal;          /* 正常空白处理 */
    word-break: normal;          /* 不在任意字符间断行（配合 fit-content 自适应宽度） */
    overflow-wrap: break-word;   /* 长单词/长串放不下时才折断 */
}
.wucha-chat-main-body .wucha-msg-user { background: #f0f4ff; color: #1a1a1a; border: none; }
.wucha-chat-main-body .wucha-msg-bot { background: #fff; color: #1a1a1a; border: 1px solid #eee; }
.wucha-chat-main-body .wucha-msg-welcome { background: #f8f9fa; color: #666; border: none; text-align: center; max-width: 80%; font-size: 13px; }
/* 昵称 */
.wucha-msg-meta { font-size: 12px; color: #999; margin-bottom: 4px; }
.wucha-msg-meta .wucha-msg-time { color: #bbb; font-size: 11px; margin-left: 6px; font-weight: normal; }
.wucha-msg-wrap.is-user .wucha-msg-meta { text-align: right; }
.wucha-msg-wrap.is-user .wucha-msg-meta .wucha-msg-time { margin-left: 0; margin-right: 6px; }

/* 引用 & 打字 */
.wucha-msg-ref { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--wucha-border); font-size: 12px; color: var(--wucha-text-muted); }
.wucha-msg-ref a { color: var(--wucha-theme); text-decoration: none; }
.wucha-msg-ref a:hover { text-decoration: underline; }
.wucha-msg-typing { background: #fff; border: 1px solid #eee; border-radius: 8px; padding: 10px 14px; display: inline-flex; gap: 4px; align-self: flex-start; }
.wucha-msg-typing span { width: 5px; height: 5px; background: #2271b1; border-radius: 50%; opacity: .4; animation: wucha-bounce 1.2s infinite ease-in-out; }
.wucha-msg-typing span:nth-child(2) { animation-delay: .15s; }
.wucha-msg-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes wucha-bounce { 0%, 60%, 100% { opacity: .4; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* 关闭后重新打开按钮 */
.wucha-inline-reopen { position: fixed; bottom: 24px; right: 24px; z-index: 99998; width: 56px; height: 56px; border-radius: 50%; background: var(--wucha-theme); color: #fff; border: none; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 16px rgba(0,0,0,.15); gap: 2px; font-size: 22px; transition: transform .2s, box-shadow .2s; font-family: inherit; }
.wucha-inline-reopen span { font-size: 9px; opacity: .9; line-height: 1; }
.wucha-inline-reopen:hover { transform: scale(1.05); box-shadow: 0 6px 24px rgba(0,0,0,.2); }

/* 模型选择器（白底灰版） */
.wucha-model-select-inline {
    border: none !important; border-radius: 6px;
    background: #f3f4f6; color: #555;
    padding: 6px 26px 6px 14px; cursor: pointer; font-size: 12px; font-weight: 500;
    flex-shrink: 0; outline: none; -webkit-appearance: none; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size: 10px 6px;
}
.wucha-model-select-inline:hover { background: #e6e8ea; }
.wucha-model-select-inline:focus { box-shadow: 0 0 0 2px var(--wucha-theme-light); border-radius: 6px; }

/* 滚动条 */
.wucha-chat-main-body::-webkit-scrollbar, .wucha-sidebar-history::-webkit-scrollbar { width: 6px; }
.wucha-chat-main-body::-webkit-scrollbar-track, .wucha-sidebar-history::-webkit-scrollbar-track { background: transparent; }
.wucha-chat-main-body::-webkit-scrollbar-thumb, .wucha-sidebar-history::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; transition: background .3s; }
.wucha-chat-main-body:hover::-webkit-scrollbar-thumb,
.wucha-sidebar-history:hover::-webkit-scrollbar-thumb,
.wucha-chat-main-body.is-scrolling::-webkit-scrollbar-thumb,
.wucha-sidebar-history.is-scrolling::-webkit-scrollbar-thumb { background: rgba(144,147,153,.35); }
.wucha-chat-main-body::-webkit-scrollbar-thumb:hover,
.wucha-sidebar-history::-webkit-scrollbar-thumb:hover { background: var(--wucha-theme); }
.wucha-chat-main-body, .wucha-sidebar-history { scrollbar-width: thin; scrollbar-color: transparent transparent; }
.wucha-chat-main-body:hover, .wucha-sidebar-history:hover,
.wucha-chat-main-body.is-scrolling, .wucha-sidebar-history.is-scrolling { scrollbar-color: rgba(144,147,153,.35) transparent; }

/* 移动端 header 紧凑化（不影响侧边栏抽屉模式，抽屉 CSS 在模板内联 style 里） */
@media (max-width: 768px) {
    .wucha-chat-main-header {
        padding: 10px 16px !important;  /* ✅ 左右 16px，和 body/input 对齐 */
        gap: 6px !important;
    }
    .wucha-chat-main-header-title { font-size: 14px !important; }
    .wucha-chat-main-header-badge { font-size: 10px; padding: 1px 6px; }
    .wucha-chat-main-header-actions { gap: 2px; }
    .wucha-chat-main-header-actions button {
        width: 28px !important; height: 28px !important; font-size: 15px !important;
    }
    /* body 和 input 左右 padding 统一 16px，和 header 对齐 */
    .wucha-chat-main-body {
        padding: 16px 16px 24px !important;
    }
    .wucha-chat-main-input {
        padding: 12px 16px 18px !important;
    }
    .wucha-model-select-inline {
        font-size: 12px !important;
        padding: 4px 26px 4px 10px !important;
        max-width: none !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }
}