/* 聊天历史面板 - 调整到右下角Live2D上方 */
#chat-history-panel {
    animation: waifu-shake 50s ease-in-out 5s infinite;
    background-color: rgba(236, 217, 188, .5);
    border: 1px solid rgba(224, 186, 140, .62);
    border-radius: 12px;
    box-shadow: 0 3px 15px 2px rgba(191, 158, 118, .2);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    opacity: 0;
    padding: 10px 15px;
    position: fixed;
    bottom: 320px; /* 调整到Live2D上方 */
    right: 20px; /* 与Live2D对齐 */
    width: 280px;
    max-height: 250px; /* 稍微减小高度避免超出屏幕 */
    word-break: break-word;
    z-index: 10001;
    overflow-y: auto;
    transition: opacity 0.5s ease, transform 0.3s ease;
    display: none;
    flex-direction: column;
    pointer-events: none;
}

#chat-history-panel.active {
    opacity: 1;
    display: flex;
    pointer-events: auto;
}

#chat-history-panel:hover {
    animation-play-state: paused;
}

/* 输入气泡 - 调整到右下角Live2D上方 */
#chat-input-bubble {
    animation: waifu-shake 30s ease-in-out 3s infinite;
    background-color: rgba(236, 217, 188, .5);
    border: 1px solid rgba(224, 186, 140, .62);
    border-radius: 12px;
    box-shadow: 0 3px 15px 2px rgba(191, 158, 118, .2);
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    opacity: 0;
    padding: 15px;
    position: fixed;
    bottom: 320px; /* 调整到Live2D上方 */
    right: 20px; /* 与Live2D对齐 */
    width: 250px;
    word-break: break-word;
    z-index: 10002;
    transition: opacity 0.5s ease, transform 0.3s ease;
    display: none;
    pointer-events: none;
}

#chat-input-bubble.active {
    opacity: 1;
    display: block;
    pointer-events: auto;
}

#chat-input-bubble:hover {
    animation-play-state: paused;
}

/* 其他样式保持不变 */
.chat-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(224, 186, 140, .4);
}

.chat-history-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #8b4513;
}

.chat-history-controls {
    display: flex;
    gap: 5px;
}

.chat-history-controls button {
    background: rgba(224, 186, 140, .5);
    border: 1px solid rgba(191, 158, 118, .4);
    border-radius: 4px;
    color: #8b4513;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.3s;
}

.chat-history-controls button:hover {
    background: rgba(224, 186, 140, .7);
    transform: scale(1.1);
}

.chat-history-messages {
    flex: 1;
    overflow-y: auto;
    max-height: 180px; /* 调整内部消息区域高度 */
}

.chat-input-bubble-header {
    font-size: 14px;
    font-weight: 600;
    color: #8b4513;
    margin-bottom: 10px;
    text-align: center;
}

#chat-input-bubble-text {
    width: calc(100% - 24px);
    border: 1px solid rgba(224, 186, 140, .62);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: all 0.3s;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.7);
    min-height: 60px;
    max-height: 100px; /* 稍微减小最大高度 */
    color: #5a3921;
    box-sizing: border-box;
}

#chat-input-bubble-text:focus {
    border-color: rgba(191, 158, 118, .8);
    box-shadow: 0 0 0 2px rgba(191, 158, 118, .2);
    background: rgba(255, 255, 255, 0.9);
}

.chat-input-bubble-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.bubble-btn {
    padding: 6px 12px;
    border: 1px solid rgba(224, 186, 140, .62);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s;
    background: rgba(236, 217, 188, .7);
    color: #8b4513;
}

.bubble-btn:hover {
    background: rgba(224, 186, 140, .8);
    transform: translateY(-1px);
}

.bubble-btn-send {
    background: rgba(139, 69, 19, 0.7);
    color: white;
    border-color: rgba(139, 69, 19, 0.5);
}

.bubble-btn-send:hover {
    background: rgba(139, 69, 19, 0.8);
}

/* 消息样式 */
.message {
    margin-bottom: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeInUp 0.3s ease;
    border: 1px solid transparent;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    background: rgba(139, 69, 19, 0.7);
    color: white;
    margin-left: 20px;
    border-bottom-right-radius: 2px;
    border: 1px solid rgba(139, 69, 19, 0.5);
}

.ai-message {
    background: rgba(236, 217, 188, 0.7);
    color: #5a3921;
    margin-right: 20px;
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(224, 186, 140, .5);
}

.thinking {
    color: #8b4513;
    font-style: italic;
    text-align: center;
    padding: 8px;
    font-size: 12px;
    background: rgba(236, 217, 188, 0.5);
    border-radius: 8px;
}

.chat-history-empty {
    text-align: center;
    color: #8b4513;
    padding: 20px 15px;
    font-size: 13px;
    opacity: 0.7;
}

.timestamp {
    font-size: 10px;
    color: rgba(139, 69, 19, 0.6);
    margin-top: 2px;
    text-align: right;
}

.ai-message .timestamp {
    text-align: left;
}

/* 历史记录按钮徽章 */
.history-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: rgba(205, 92, 92, 0.8);
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* 滚动条样式 */
.chat-history-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-history-messages::-webkit-scrollbar-track {
    background: rgba(236, 217, 188, 0.3);
    border-radius: 3px;
}

.chat-history-messages::-webkit-scrollbar-thumb {
    background: rgba(191, 158, 118, 0.5);
    border-radius: 3px;
}

.chat-history-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(191, 158, 118, 0.7);
}

#chat-input-bubble-text::-webkit-scrollbar {
    width: 6px;
}

#chat-input-bubble-text::-webkit-scrollbar-track {
    background: rgba(236, 217, 188, 0.3);
    border-radius: 3px;
}

#chat-input-bubble-text::-webkit-scrollbar-thumb {
    background: rgba(191, 158, 118, 0.5);
    border-radius: 3px;
}

#chat-input-bubble-text::-webkit-scrollbar-thumb:hover {
    background: rgba(191, 158, 118, 0.7);
}

/* Live2D的摇动动画 */
@keyframes waifu-shake {
    0%, 40%, 60%, 80% {
        transform: rotate(0deg);
    }
    2% {
        transform: rotate(1deg);
    }
    42% {
        transform: rotate(-1deg);
    }
    62% {
        transform: rotate(0.5deg);
    }
    82% {
        transform: rotate(-0.5deg);
    }
}

/* 自动关闭相关样式 */
.auto-close-indicator {
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: rgba(139, 69, 19, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

.auto-close-progress {
    height: 100%;
    background: rgba(139, 69, 19, 0.6);
    width: 100%;
    transition: width 5s linear;
}

.auto-close-progress.running {
    width: 0%;
}

/* 响应式调整 - 确保在小屏幕上也能正常显示 */
@media (max-height: 800px) {
    #chat-history-panel {
        bottom: 280px;
        max-height: 200px;
    }
    
    #chat-input-bubble {
        bottom: 280px;
    }
    
    .chat-history-messages {
        max-height: 150px;
    }
}

@media (max-height: 600px) {
    #chat-history-panel {
        bottom: 250px;
        max-height: 150px;
    }
    
    #chat-input-bubble {
        bottom: 250px;
    }
    
    .chat-history-messages {
        max-height: 120px;
    }
}