/* --- START OF FILE frontend.css --- */

/* =========================================
   1. 整体布局容器 (App Container)
   ========================================= */
.aic-app-container {
    display: flex;
    height: 600px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    border: 1px solid #eee;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    font-size: var(--aic-font-size, 15px);
}

/* =========================================
   2. 侧边栏 (Sidebar)
   ========================================= */
.aic-sidebar {
    width: 260px;
    background: #f8f9fa;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 20;
}

.aic-sidebar-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
}

/* 新建会话按钮 */
.aic-btn-block {
    width: 100%;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}
.aic-btn-block:hover { background: #f0f0f0; border-color: #ccc; }

/* 会话列表 */
.aic-session-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.aic-session-item {
    padding: 10px 12px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
    position: relative;
}
.aic-session-item:hover { background: #e9ecef; }
.aic-session-item.active { background: #e7f1ff; color: var(--aic-primary, #0d6efd); font-weight: 500; }

.aic-session-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 5px;
}
/* 重命名输入框 */
.aic-session-title input {
    width: 100%;
    border: 1px solid var(--aic-primary, #0d6efd);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    background: #fff;
}

/* 会话操作按钮 (重命名/删除) */
.aic-session-actions {
    display: none; /* 默认隐藏 */
    gap: 4px;
    align-items: center;
}
.aic-session-item:hover .aic-session-actions,
.aic-session-item.active .aic-session-actions {
    display: flex; /* 悬停或激活时显示 */
}

.aic-session-btn {
    color: #999;
    font-size: 14px;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
}
.aic-session-btn:hover { color: #333; background: rgba(0,0,0,0.05); }
.aic-session-btn.aic-delete-session:hover { color: #d63638; }

/* =========================================
   3. 主聊天区域 (Chat Wrapper)
   ========================================= */
.aic-chat-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: none;
    box-shadow: none;
    height: 100%;
    margin: 0;
    border-radius: 0;
    background: #fff;
    position: relative;
    min-width: 0;
}

/* 移动端顶部栏 */
.aic-mobile-header {
    display: none; /* 桌面端隐藏 */
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    align-items: center;
    gap: 10px;
    background: #fff;
    z-index: 10;
}
.aic-current-session-title {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 消息滚动区域 */
.aic-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

/* 欢迎卡片 */
.aic-welcome-card {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}
.aic-welcome-icon span {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: var(--aic-primary, #0d6efd);
    opacity: 0.8;
}
.aic-welcome-text {
    margin-top: 15px;
    font-size: 16px;
    line-height: 1.5;
}

/* =========================================
   4. 消息气泡与工具栏 (Messages & Tools)
   ========================================= */
.aic-msg {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    animation: aic-fade-in 0.3s ease;
    width: 100%;
    box-sizing: border-box;
    align-items: flex-start; /* 顶部对齐 */
}

/* 用户消息反转排列：头像 -> 内容 -> 工具栏 */
.aic-msg-user { flex-direction: row-reverse; }

.aic-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.aic-msg-ai .aic-avatar { background: #333; color: #fff; }
.aic-msg-user .aic-avatar { background: var(--aic-primary, #0d6efd); color: #fff; }

.aic-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--aic-radius, 12px);
    font-size: 1em;
    line-height: 1.6;
    position: relative;
    word-wrap: break-word;
}

.aic-msg-ai .aic-content {
    background: var(--aic-ai-bg, #ffffff);
    border: 1px solid #e5e5e5;
    color: #333;
    border-top-left-radius: 2px;
}

.aic-msg-user .aic-content {
    background: var(--aic-user-bg, #0d6efd);
    color: #fff;
    border-top-right-radius: 2px;
}

/* --- 消息工具栏 (编辑/分支/删除) --- */
.aic-msg-tools {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0; /* 默认隐藏 */
    transition: opacity 0.2s ease;
    padding-top: 5px; /* 稍微下移一点，对齐气泡顶部 */
    
    /* 样式美化 */
    background: #f5f5f5;
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 4px 6px;
    margin-top: 10px;
}

/* 鼠标悬停在消息行时显示工具栏 */
.aic-msg:hover .aic-msg-tools { opacity: 1; }

.aic-tool-btn {
    cursor: pointer;
    color: #999;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.aic-tool-btn:hover { background: rgba(0,0,0,0.05); color: #333; }
.aic-tool-btn.aic-action-edit:hover { color: var(--aic-primary, #0d6efd); }
.aic-tool-btn.aic-action-branch:hover { color: #198754; }
.aic-tool-btn.aic-action-delete:hover { color: #dc3545; }

/* =========================================
   5. 编辑模式样式 (Edit Mode)
   ========================================= */
.aic-edit-textarea {
    width: 100%;
    border: 1px solid var(--aic-primary, #0d6efd);
    border-radius: 6px;
    padding: 8px;
    font-family: inherit;
    font-size: inherit;
    resize: vertical;
    margin-bottom: 8px;
    min-height: 60px;
    color: #333;
    background: #fff;
    box-sizing: border-box;
}

.aic-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* 通用小按钮 */
.aic-btn-sm {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid #ddd;
    background: #fff;
    color: #555;
    transition: all 0.2s;
    font-weight: 500;
}
.aic-btn-sm:hover { background: #f5f5f5; color: #333; }

/* 覆盖按钮 (蓝色) - Update & Overwrite */
.aic-submit-overwrite {
    background: #fff;
    color: var(--aic-primary, #0d6efd);
    border-color: var(--aic-primary, #0d6efd);
}
.aic-submit-overwrite:hover {
    background: var(--aic-primary, #0d6efd);
    color: #fff;
}

/* 保留按钮 (橙色) - Update & Keep */
.aic-submit-keep {
    background: #fff;
    color: #f59e0b; /* Amber-500 */
    border-color: #f59e0b;
}
.aic-submit-keep:hover {
    background: #f59e0b;
    color: #fff;
}

/* =========================================
   6. Markdown & 代码高亮
   ========================================= */
.aic-content p { margin: 0 0 10px 0; }
.aic-content p:last-child { margin: 0; }
.aic-content pre {
    background: #1e1e1e;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    color: #d4d4d4;
    font-family: Consolas, monospace;
    margin: 10px 0;
}
.aic-content code {
    background: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: Consolas, monospace;
    font-size: 0.9em;
}
.aic-msg-user .aic-content code { color: #fff; background: rgba(255,255,255,0.2); }
.aic-msg-user .aic-content a { color: #fff; text-decoration: underline; }
.aic-user-upload-img { max-width: 200px; border-radius: 8px; margin-top: 8px; border: 2px solid rgba(255,255,255,0.5); }

.aic-audio-player {
    margin-top: 10px;
    width: 100%;
    max-width: 300px;
    height: 36px;
    border-radius: 18px;
    display: block;
    outline: none;
}

/* =========================================
   7. 输入区域 (Input Area)
   ========================================= */
.aic-input-area-wrapper {
    padding: 15px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    box-sizing: border-box;
}

.aic-input-bar {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f0f2f5;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: border 0.2s, box-shadow 0.2s;
    position: relative;
    min-width: 200px;
    box-sizing: border-box;
}
.aic-input-bar:focus-within { 
    border-color: var(--aic-primary, #0d6efd);
    background: #fff; 
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05); 
}

.aic-inner-btn {
    color: #999;
    cursor: pointer;
    display: flex;
    align-items: center;
    padding-bottom: 4px;
    transition: color 0.2s;
}
.aic-inner-btn:hover { color: #666; }

#aic-chat-input {
    flex: 1;
    background: transparent;
    border: none;
    resize: none;
    height: 24px;
    max-height: 120px;
    padding: 2px;
    font-size: 15px;
    outline: none;
    line-height: 1.5;
    color: #333;
    width: 100%;
}

.aic-mic-btn {
    color: #999;
    cursor: pointer;
    padding-bottom: 4px;
    transition: color 0.2s;
}
.aic-mic-btn:hover { color: var(--aic-primary, #0d6efd); }
.aic-mic-btn.listening { color: #d63638; animation: pulse 1.5s infinite; }

#aic-chat-send-btn {
    height: 42px;
    padding: 0 20px;
    border-radius: 8px;
    border: none;
    background: var(--aic-primary, #0d6efd);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s;
    white-space: nowrap;
}
#aic-chat-send-btn:hover { opacity: 0.9; }
#aic-chat-send-btn.aic-btn-loading { opacity: 0.7; cursor: not-allowed; }

/* 消息底部操作 (TTS & Copy) */
.aic-msg-actions {
    position: relative;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}

.aic-tts-btn, .aic-copy-btn {
    cursor: pointer;
    color: #999;
    transition: color 0.2s;
    padding: 5px;
}
.aic-tts-btn:hover, .aic-copy-btn:hover { color: var(--aic-primary, #0d6efd); }
.aic-tts-btn.playing { color: var(--aic-primary, #0d6efd); animation: none; }

/* 快捷指令 */
.aic-quick-actions-container {
    padding: 10px 15px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    scrollbar-width: none;
}
.aic-quick-actions-container::-webkit-scrollbar { display: none; }
.aic-qa-btn {
    background: #f0f2f5;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.aic-qa-btn:hover {
    background: var(--aic-primary, #0d6efd);
    color: #fff;
    border-color: var(--aic-primary, #0d6efd);
}

/* 上传预览 */
#aic-upload-preview {
    padding: 10px;
    background: #f8f9fa;
    margin-top: 10px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #eee;
    width: 100%;
    box-sizing: border-box;
}
#aic-preview-img { height: 50px; border-radius: 4px; }
.remove-file { cursor: pointer; color: #999; }

#aic-audio-preview-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #2271b1;
    background: #e7f5ff;
    padding: 5px 10px;
    border-radius: 4px;
    margin-left: 10px;
}

.aic-footer-info {
    text-align: center;
    font-size: 11px;
    color: #ccc;
    margin-top: 8px;
    width: 100%;
}

@keyframes aic-fade-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* =========================================
   8. 移动端适配 (Mobile)
   ========================================= */
@media (max-width: 768px) {
    .aic-app-container {
        position: fixed !important;
        top: 0; left: 0; width: 100% !important; height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        z-index: 999999;
        border: none !important;
    }
    .aic-sidebar {
        position: absolute;
        left: 0; top: 0; bottom: 0;
        z-index: 30;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        width: 80%;
        max-width: 300px;
    }
    .aic-sidebar.open { transform: translateX(0); }
    .aic-mobile-header { display: flex; }
    
    /* 移动端工具栏常显 */
    .aic-msg-tools {
        opacity: 1;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
        margin-top: 0;
    }
}