/* static/css/ai_agent.css - Nice Cafe AI Agent Interface Styling */

/* 1. 悬浮气泡按钮 */
.ai-agent-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2DCCD3, #1FA3A9);
    box-shadow: 0 4px 20px rgba(45, 204, 211, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.ai-agent-bubble:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 24px rgba(45, 204, 211, 0.6);
}

/* 呼吸灯特效 */
.ai-agent-bubble::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 2px solid #1FA3A9;
    opacity: 0.8;
    animation: ai-pulse 2s infinite;
    pointer-events: none;
}

@keyframes ai-pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.08);
        opacity: 0.3;
    }
    100% {
        transform: scale(1.2);
        opacity: 0;
    }
}

.ai-agent-bubble svg {
    color: #ffffff;
    width: 26px;
    height: 26px;
    transition: transform 0.3s ease;
}

/* 2. AI 助手主面板 */
.ai-agent-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    height: 580px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 120px);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

.ai-agent-panel.show {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* 头部栏 */
.ai-agent-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(45, 204, 211, 0.08), rgba(31, 163, 169, 0.08));
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-agent-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-agent-title-text {
    font-weight: 600;
    font-size: 15px;
    color: #1f2937;
}

.ai-agent-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #10b981;
}

.ai-agent-status-dot {
    width: 6px;
    height: 6px;
    background-color: #10b981;
    border-radius: 50%;
    animation: status-glow 1.5s infinite alternate;
}

@keyframes status-glow {
    0% { opacity: 0.4; }
    100% { opacity: 1; }
}

.ai-agent-close {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-agent-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #1f2937;
}

/* 消息对话区域 */
.ai-agent-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 隐藏滚动条 */
.ai-agent-body::-webkit-scrollbar {
    width: 6px;
}
.ai-agent-body::-webkit-scrollbar-track {
    background: transparent;
}
.ai-agent-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

/* 单条消息包装 */
.ai-msg {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 85%;
}

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

.ai-msg.user {
    align-self: flex-end;
}

/* 消息气泡 */
.ai-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-all;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
}

.ai-msg.system .ai-bubble {
    background: #ffffff;
    color: #374151;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0,0,0,0.05);
}

.ai-msg.user .ai-bubble {
    background: linear-gradient(135deg, #2DCCD3, #1FA3A9);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

/* 图片附件预览 */
.ai-attached-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ai-attached-img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s;
}

.ai-attached-img:hover {
    transform: scale(1.05);
}



/* 输入框和控制面板 */
.ai-agent-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* 待上传图片缩略图区 */
.ai-upload-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ai-preview-item {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    overflow: hidden;
}

.ai-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    border: none;
}

.ai-preview-remove:hover {
    background: rgba(239, 68, 68, 0.8);
}

/* 输入栏 */
.ai-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-input-textarea {
    flex: 1;
    height: 38px;
    max-height: 100px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    font-size: 13px;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.ai-input-textarea:focus {
    border-color: #2DCCD3;
}

.ai-btn-action {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-btn-action:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.ai-btn-send {
    background: linear-gradient(135deg, #2DCCD3, #1FA3A9);
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 8px rgba(45, 204, 211, 0.3);
}

.ai-btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(45, 204, 211, 0.5);
}

.ai-btn-send:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* 拖拽状态遮罩 */
.ai-drag-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(45, 204, 211, 0.95);
    color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 10001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    border-radius: 20px;
}

.ai-agent-panel.drag-over .ai-drag-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* 思考/处理中动画 */
.ai-typing-loader {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 18px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid rgba(0,0,0,0.05);
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.ai-typing-dot {
    width: 6px;
    height: 6px;
    background: #2DCCD3;
    border-radius: 50%;
    animation: ai-dot-bounce 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes ai-dot-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* 暗色模式微调 (检测是否跟随系统或主体样式) */
.dark-theme .ai-agent-panel {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(255,255,255,0.1);
    color: #f1f5f9;
}

.dark-theme .ai-agent-title-text {
    color: #f3f4f6;
}

.dark-theme .ai-msg.system .ai-bubble {
    background: #1e293b;
    color: #e2e8f0;
    border-color: rgba(255,255,255,0.05);
}

.dark-theme .ai-agent-footer {
    background: #0f172a;
    border-color: rgba(255,255,255,0.08);
}

.dark-theme .ai-input-textarea {
    background: #1e293b;
    border-color: rgba(255,255,255,0.15);
    color: #f3f4f6;
}

.dark-theme .ai-btn-action:hover {
    background: #1e293b;
    color: #f3f4f6;
}

/* 5. 自由缩放及拉伸样式 */
.ai-resizer-tl {
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    z-index: 10005;
    border-top: 2px solid rgba(45, 204, 211, 0.4);
    border-left: 2px solid rgba(45, 204, 211, 0.4);
    border-top-left-radius: 4px;
}

/* 历史卡片样式 */
.ai-history-card {
    padding: 12px 14px;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.01);
}

.ai-history-card:hover {
    border-color: #2DCCD3;
    background: rgba(45, 204, 211, 0.03);
    transform: translateY(-1px);
}

.ai-history-title {
    font-size: 13px;
    color: #374151;
    font-weight: 500;
}

.ai-history-delete-btn {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ai-history-delete-btn:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

/* 6. 移动端响应式适配 */
@media (max-width: 768px) {
    .ai-agent-bubble {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
    }
    .ai-agent-panel {
        bottom: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        transform: translateY(100%) !important;
    }
    .ai-agent-panel.show {
        transform: translateY(0) !important;
    }
    .ai-resizer-tl {
        display: none !important; /* 手机上禁用边缘手动拉伸 */
    }
    .ai-agent-body {
        padding: 12px 14px !important;
    }
    .ai-bubble {
        max-width: 92% !important;
        font-size: 13px !important;
        padding: 10px 14px !important;
    }
    /* 表格在移动端自适应滚动 */
    .ai-bubble div[style*="overflow-x: auto"] {
        margin: 6px 0 !important;
    }
    .ai-bubble table {
        font-size: 11px !important;
    }
    .ai-bubble th, .ai-bubble td {
        padding: 6px 4px !important;
    }
}

/* 自适应宽屏布局，防止表格在气泡中拥挤 */
.ai-msg-wide {
    max-width: 100% !important;
    width: 100% !important;
    align-self: stretch !important;
}
.ai-msg-wide .ai-bubble {
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
}
