/* ============================================================================
 * SHOA Chat Widget · 全站浮动 AI 助手
 * 国际化抽屉式设计 (参考 Intercom / Drift / Crisp)
 * ========================================================================= */

/* ---------- 主题变量（与全站共享 :root 颜色，不污染） ---------- */
#shoa-widget-root {
    --w-gold: #b08840;
    --w-gold-light: #e6c66e;
    --w-gold-dark: #8a6a32;
    --w-navy: #0f2042;
    --w-bg: #ffffff;
    --w-bg-sub: #faf8f3;
    --w-text: #1f2937;
    --w-text-mute: #6b7280;
    --w-border: #e5e7eb;
    --w-bubble-user: linear-gradient(135deg, #b08840, #d4a653);
    --w-bubble-ai: #f5f1e8;
    --w-shadow-fab: 0 8px 24px rgba(176, 136, 64, 0.4),
                    0 2px 8px rgba(15, 32, 66, 0.15);
    --w-shadow-panel: 0 24px 56px rgba(15, 32, 66, 0.25),
                      0 4px 16px rgba(15, 32, 66, 0.12);
}
[data-theme="dark"] #shoa-widget-root {
    --w-bg: #1a1f2e;
    --w-bg-sub: #232a3a;
    --w-text: #e5e7eb;
    --w-text-mute: #9ca3af;
    --w-border: #2d3548;
    --w-bubble-ai: #2a3142;
}

/* ---------- 容器（fixed 锚定） ---------- */
#shoa-widget-root {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9990;
    font-family: 'Inter', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
}

/* 在 ai_academy 页隐藏 widget (避免冗余) */
body[data-no-widget] #shoa-widget-root { display: none !important; }

/* ===========================================================================
 *  FAB 圆球
 * ======================================================================== */
.shoa-fab {
    position: relative;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, var(--w-gold), var(--w-gold-light));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--w-shadow-fab);
    transition: transform .25s cubic-bezier(.34, 1.56, .64, 1),
                box-shadow .25s ease,
                opacity .25s ease;
    animation: shoaBreathe 3.2s ease-in-out infinite;
    outline: none;
}
.shoa-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 32px rgba(176, 136, 64, .55),
                0 4px 12px rgba(15, 32, 66, .2);
}
.shoa-fab:active { transform: scale(.96); }
.shoa-fab:focus-visible {
    outline: 3px solid rgba(176, 136, 64, .5);
    outline-offset: 4px;
}
.shoa-fab svg {
    width: 28px;
    height: 28px;
    stroke-width: 2;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .15));
}

/* 光晕涟漪：双层 pulse 让小球感觉「活着」 */
.shoa-fab::before,
.shoa-fab::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--w-gold);
    opacity: 0;
    animation: shoaRipple 2.4s ease-out infinite;
    pointer-events: none;
}
.shoa-fab::after { animation-delay: 1.2s; }

/* 隐藏 FAB 当面板打开时 */
#shoa-widget-root.open .shoa-fab {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

/* 小红点通知（预留，可选） */
.shoa-fab-dot {
    position: absolute;
    top: 8px; right: 8px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 2px #fff;
    display: none;
}
.shoa-fab.has-notif .shoa-fab-dot { display: block; }

/* ===========================================================================
 *  抽屉面板
 * ======================================================================== */
.shoa-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 380px;
    height: min(620px, calc(100vh - 48px));
    background: var(--w-bg);
    border-radius: 18px;
    box-shadow: var(--w-shadow-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(.96);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .22s ease, transform .22s cubic-bezier(.34, 1.56, .64, 1);
}
#shoa-widget-root.open .shoa-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---------- Header ---------- */
.shoa-header {
    position: relative;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--w-navy) 0%, #1a2d57 60%, var(--w-gold-dark) 130%);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
}
.shoa-header::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at top right, rgba(230, 198, 110, .35), transparent 60%);
    pointer-events: none;
}
.shoa-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--w-gold), var(--w-gold-light));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
    flex-shrink: 0;
    z-index: 1;
}
.shoa-title {
    flex: 1;
    min-width: 0;
    z-index: 1;
}
.shoa-title-name {
    font-size: .95rem;
    font-weight: 600;
    line-height: 1.2;
    display: flex;
    align-items: center;
    gap: 6px;
}
.shoa-title-name::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, .3);
    animation: shoaPulse 2s ease-in-out infinite;
}
.shoa-title-sub {
    font-size: .72rem;
    opacity: .82;
    line-height: 1.3;
    margin-top: 2px;
}
.shoa-header-actions {
    display: flex;
    gap: 4px;
    z-index: 1;
}
.shoa-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, transform .15s ease;
}
.shoa-icon-btn:hover { background: rgba(255, 255, 255, .22); }
.shoa-icon-btn:active { transform: scale(.92); }
.shoa-icon-btn svg { width: 16px; height: 16px; }

/* ---------- 消息流 ---------- */
.shoa-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    background: var(--w-bg-sub);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.shoa-msgs::-webkit-scrollbar { width: 6px; }
.shoa-msgs::-webkit-scrollbar-thumb { background: var(--w-border); border-radius: 3px; }
.shoa-msgs::-webkit-scrollbar-thumb:hover { background: var(--w-text-mute); }

/* 欢迎卡 */
.shoa-welcome {
    text-align: center;
    padding: 12px 8px 8px;
    color: var(--w-text);
}
.shoa-welcome-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--w-gold), var(--w-gold-light));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(176, 136, 64, .3);
}
.shoa-welcome-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--w-text);
}
.shoa-welcome-sub {
    font-size: .8rem;
    color: var(--w-text-mute);
    line-height: 1.5;
    margin-bottom: 14px;
}
.shoa-suggest-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}
.shoa-suggest-item {
    text-align: left;
    padding: 10px 12px;
    background: var(--w-bg);
    border: 1px solid var(--w-border);
    border-radius: 10px;
    font-size: .82rem;
    color: var(--w-text);
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1.4;
}
.shoa-suggest-item:hover {
    border-color: var(--w-gold);
    background: var(--w-bubble-ai);
    transform: translateX(2px);
}

/* 消息气泡 */
.shoa-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 100%;
    animation: shoaFadeUp .25s ease;
}
.shoa-msg.user { flex-direction: row-reverse; }
.shoa-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 700;
}
.shoa-msg.ai .shoa-msg-avatar {
    background: linear-gradient(135deg, var(--w-gold), var(--w-gold-light));
    color: #fff;
}
.shoa-msg.user .shoa-msg-avatar {
    background: var(--w-navy);
    color: #fff;
}
[data-theme="dark"] .shoa-msg.user .shoa-msg-avatar {
    background: #4a5568;
}
.shoa-msg-bubble {
    max-width: 78%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: .85rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.shoa-msg.ai .shoa-msg-bubble {
    background: var(--w-bubble-ai);
    color: var(--w-text);
    border-bottom-left-radius: 4px;
}
.shoa-msg.user .shoa-msg-bubble {
    background: var(--w-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.shoa-msg-bubble p { margin: 0 0 .5em; }
.shoa-msg-bubble p:last-child { margin-bottom: 0; }
.shoa-msg-bubble code {
    background: rgba(0, 0, 0, .08);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: .82em;
    font-family: monospace;
}
.shoa-msg.user .shoa-msg-bubble code { background: rgba(255, 255, 255, .25); }
.shoa-msg-bubble pre {
    background: rgba(0, 0, 0, .85);
    color: #e5e7eb;
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: .78em;
    margin: 6px 0;
}
.shoa-msg-bubble a {
    color: var(--w-gold);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.shoa-msg.user .shoa-msg-bubble a { color: #fff; }
.shoa-msg-bubble img.media-img { max-width: 100%; border-radius: 8px; margin: 4px 0; }
.shoa-msg-bubble video.media-video,
.shoa-msg-bubble audio.media-audio { max-width: 100%; margin: 4px 0; border-radius: 6px; }

/* 思考中指示器 */
.shoa-thinking {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--w-text-mute);
    font-size: .82rem;
}
.shoa-thinking .spin {
    width: 14px; height: 14px;
    border: 2px solid var(--w-border);
    border-top-color: var(--w-gold);
    border-radius: 50%;
    animation: shoaSpin 0.8s linear infinite;
}
.shoa-thinking .dots::after {
    content: "";
    display: inline-block;
    min-width: 1.2em;
    text-align: left;
    animation: shoaDots 1.4s steps(4, end) infinite;
}

/* ---------- Composer ---------- */
.shoa-composer {
    padding: 10px 12px 12px;
    background: var(--w-bg);
    border-top: 1px solid var(--w-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.shoa-textarea {
    flex: 1;
    min-height: 36px;
    max-height: 120px;
    padding: 8px 12px;
    border: 1.5px solid var(--w-border);
    border-radius: 18px;
    font-size: .88rem;
    font-family: inherit;
    color: var(--w-text);
    background: var(--w-bg-sub);
    resize: none;
    outline: none;
    line-height: 1.4;
    transition: border-color .15s ease, background .15s ease;
}
.shoa-textarea:focus {
    border-color: var(--w-gold);
    background: var(--w-bg);
}
.shoa-textarea::placeholder { color: var(--w-text-mute); }

.shoa-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--w-gold), var(--w-gold-light));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform .15s ease, opacity .15s ease;
    box-shadow: 0 2px 8px rgba(176, 136, 64, .3);
}
.shoa-send:hover { transform: scale(1.08); }
.shoa-send:active { transform: scale(.92); }
.shoa-send:disabled {
    background: var(--w-border);
    color: var(--w-text-mute);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}
.shoa-send svg { width: 16px; height: 16px; }

.shoa-footer {
    text-align: center;
    padding: 4px 0 8px;
    font-size: .68rem;
    color: var(--w-text-mute);
    background: var(--w-bg);
    letter-spacing: .03em;
}
.shoa-footer a {
    color: var(--w-gold);
    text-decoration: none;
}

/* ===========================================================================
 *  动画
 * ======================================================================== */
@keyframes shoaBreathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}
@keyframes shoaRipple {
    0%   { transform: scale(1);   opacity: .65; }
    100% { transform: scale(1.7); opacity: 0; }
}
@keyframes shoaPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.3); opacity: .6; }
}
@keyframes shoaFadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes shoaSpin {
    to { transform: rotate(360deg); }
}
@keyframes shoaDots {
    0%   { content: ""; }
    25%  { content: "."; }
    50%  { content: ".."; }
    75%  { content: "..."; }
    100% { content: ""; }
}

/* ===========================================================================
 *  响应式 · 移动端全屏接管
 * ======================================================================== */
@media (max-width: 768px) {
    #shoa-widget-root {
        right: 16px;
        bottom: 16px;
    }
    .shoa-panel {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        transform-origin: bottom right;
    }
}

/* 全屏模式（PC 也可由用户主动展开） */
#shoa-widget-root.fullscreen .shoa-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
}

/* ===========================================================================
 *  减少动效偏好（无障碍）
 * ======================================================================== */
@media (prefers-reduced-motion: reduce) {
    .shoa-fab { animation: none; }
    .shoa-fab::before, .shoa-fab::after { animation: none; }
    .shoa-title-name::after { animation: none; }
    .shoa-msg, .shoa-panel { animation: none; transition: opacity .15s; }
}
