/* === AI 助手面板 === */

/* ---- AI 顶部按钮 ---- */
.ai-top-btn {
    display: flex; align-items: center; gap: 4px;
    height: 34px; padding: 0 10px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e; border: 1px solid #fcd34d;
    border-radius: 8px; font-size: 12px; font-weight: 600;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-top-btn:hover {
    background: linear-gradient(135deg, #fde68a, #fbbf24);
    color: #78350f;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(251, 191, 36, 0.35);
}
.ai-top-btn:active { transform: translateY(0) scale(0.96); }
.ai-top-btn svg {
    color: #d97706;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    filter: drop-shadow(0 1px 1px rgba(217, 119, 6, 0.15));
}
.ai-top-btn:hover svg {
    transform: scale(1.15) rotate(-8deg);
    filter: drop-shadow(0 2px 3px rgba(217, 119, 6, 0.25));
}

/* ---- AI 助手浮动窗口 ---- */
.ai-panel {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 440px;
    height: 580px;
    max-height: calc(100vh - 100px);
    z-index: 45;
    background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
    border: 1px solid #e2e6ec;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 16px 56px rgba(0, 0, 0, 0.1),
        0 6px 16px rgba(0, 0, 0, 0.04),
        0 0 0 1px rgba(255, 255, 255, 0.8) inset;
    overflow: hidden;
    user-select: none;
    transition: box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, box-shadow;
}
.ai-panel.hidden { display: none !important; }
.ai-panel.dragging {
    opacity: 0.92;
    cursor: grabbing;
    box-shadow: 0 24px 72px rgba(0, 0, 0, 0.15);
    border-color: #bfdbfe;
}
.ai-panel:not(.hidden) {
    animation: cardFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* AI 面板头部 */
.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 14px 0 18px;
    border-bottom: 1px solid #eef1f5;
    flex-shrink: 0;
    cursor: grab;
    background: linear-gradient(180deg, #f8fafc 0%, #f4f6f9 100%);
}
.ai-panel-header:active { cursor: grabbing; }

.ai-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
    pointer-events: none;
}
/* AI 标题图标容器 */
.ai-panel-title-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    box-shadow: 0 2px 6px rgba(251, 191, 36, 0.2);
}
.ai-panel-title-icon svg { color: #d97706; }

.ai-panel-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: #a0a8b8;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}
.ai-panel-close:hover {
    background: #f1f4f8;
    color: #475569;
    transform: rotate(90deg);
}

/* AI 模式切换栏 */
.ai-panel-modes {
    display: flex;
    gap: 4px;
    padding: 8px 14px;
    border-bottom: 1px solid #eef1f5;
    flex-shrink: 0;
    overflow-x: auto;
    background: linear-gradient(180deg, #fdfdfe 0%, #f8fafc 100%);
}
.ai-mode-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid transparent;
    color: #8b95a5;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    letter-spacing: 0.3px;
    position: relative;
}
.ai-mode-btn:hover {
    background: rgba(74, 158, 255, 0.05);
    color: #4a5568;
    border-color: rgba(74, 158, 255, 0.1);
}
.ai-mode-btn.active {
    background: linear-gradient(135deg, #eef5ff, #e8f2ff);
    color: #2b6cb0;
    border-color: #c7dffc;
    font-weight: 600;
    box-shadow: 0 1px 6px rgba(74, 158, 255, 0.12), 0 0 0 1px rgba(74, 158, 255, 0.05);
}
.ai-mode-btn.active::before {
    content: "";
    position: absolute;
    bottom: -9px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #4a9eff, transparent);
    border-radius: 2px;
}
.ai-mode-btn:active { transform: scale(0.96); }

/* ---- Tab 内容区域 ---- */
.ai-tab-contents {
    flex: 1;
    position: relative;
    overflow: hidden;
}
.ai-tab-content {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
}
.ai-tab-content.active { display: flex; }

/* 对话和问答：聊天滚动区域 */
.ai-chat-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: linear-gradient(180deg, #f6f8fb 0%, #f4f6f9 100%);
}

/* 翻译和总结：结果滚动区域 */
.ai-result-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: linear-gradient(180deg, #f6f8fb 0%, #f4f6f9 100%);
}

/* 底部输入栏（对话、问答） */
.ai-chat-inputbar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    padding: 10px 14px;
    border-top: 1px solid #eef1f5;
    flex-shrink: 0;
    background: linear-gradient(180deg, #fafbfc 0%, #f8fafc 100%);
}
.ai-chat-inputbar textarea {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
    padding: 9px 14px;
    background: #f0f2f6;
    color: #1e293b;
    border: 1px solid #e2e6ec;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    resize: none;
    outline: none;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
}
.ai-chat-inputbar textarea:focus {
    border-color: #4a9eff;
    background: #fff;
    box-shadow: 0 0 0 4px rgba(74, 158, 255, 0.1);
}
.ai-chat-inputbar textarea::placeholder { color: #a0a8b8; }
.ai-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #4a9eff, #3a8eef);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 3px 10px rgba(74, 158, 255, 0.3);
}
.ai-send-btn:hover {
    background: linear-gradient(135deg, #3a8eef, #2a7eef);
    transform: translateY(-2px) scale(1.08);
    box-shadow: 0 6px 18px rgba(74, 158, 255, 0.4);
}
.ai-send-btn:active { transform: translateY(0) scale(0.95); }
.ai-send-btn:disabled {
    opacity: 0.4;
    transform: none;
    box-shadow: none;
    cursor: not-allowed;
}

/* 拖放层（翻译、总结、问答） */
.ai-drop-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 78px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: #a0a8b8;
    font-size: 13px;
    font-weight: 500;
    background: rgba(246, 248, 251, 0.97);
    border: 2px dashed #d4d8e0;
    margin: 14px 14px 0 14px;
    border-radius: 14px;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    animation: breathe 3s ease-in-out infinite;
}
.ai-drop-layer svg {
    color: #c0c8d5;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.04));
    transition: all 0.3s;
}
.ai-tab-content.has-file .ai-drop-layer {
    display: none;
}
.ai-panel.ai-drag-over .ai-drop-layer {
    border-color: #4a9eff;
    color: #4a9eff;
    background: rgba(239, 246, 255, 0.95);
    animation: none;
    transform: scale(1.01);
    box-shadow: 0 0 24px rgba(74, 158, 255, 0.12);
}
.ai-panel.ai-drag-over .ai-drop-layer svg {
    color: #4a9eff;
    filter: drop-shadow(0 4px 8px rgba(74,158,255,0.2));
}

/* ---- AI 消息样式 ---- */
.ai-msg {
    display: flex;
    margin-bottom: 6px;
    animation: msgIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: calc(var(--msg-index, 0) * 0.05s);
    will-change: transform, opacity;
}
.ai-msg:last-child { margin-bottom: 0; }

/* 用户消息 - 右侧蓝色气泡 */
.ai-msg.user {
    justify-content: flex-end;
}
.ai-msg.user .ai-bubble {
    background: linear-gradient(135deg, #4a9eff, #3a8eef);
    color: #fff;
    border-radius: 16px 16px 4px 16px;
    max-width: 80%;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: 0 3px 12px rgba(74, 158, 255, 0.22);
    letter-spacing: 0.2px;
}

/* AI 消息 - 左侧白色气泡 */
.ai-msg.ai {
    justify-content: flex-start;
}
.ai-msg.ai .ai-bubble {
    background: #fff;
    color: #334155;
    border-radius: 16px 16px 16px 4px;
    max-width: 86%;
    padding: 14px 18px;
    font-size: 13px;
    line-height: 1.7;
    word-break: break-word;
    border: 1px solid #eaeef3;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-msg.ai .ai-bubble:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

/* 系统提示消息 */
.ai-msg.system {
    justify-content: center;
    margin: 10px 0;
}
.ai-msg.system .ai-bubble {
    background: linear-gradient(135deg, #fef9e7, #fef3c7);
    color: #926c00;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid #fde68a;
    box-shadow: 0 1px 4px rgba(251, 191, 36, 0.08);
    letter-spacing: 0.3px;
}

/* AI 消息中的代码块 */
.ai-msg.ai .ai-bubble pre {
    background: #f4f6f9;
    border: 1px solid #e2e6ec;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    font-size: 12px;
    margin: 10px 0;
    line-height: 1.5;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}
.ai-msg.ai .ai-bubble code {
    background: #eef1f5;
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 12px;
    color: #c93546;
    font-weight: 500;
}
.ai-msg.ai .ai-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-weight: 400;
}
.ai-msg.ai .ai-bubble p { margin: 0 0 8px 0; }
.ai-msg.ai .ai-bubble p:last-child { margin-bottom: 0; }
.ai-msg.ai .ai-bubble strong { color: #1e293b; font-weight: 600; }

/* 翻译/总结结果卡片 */
.ai-result-box {
    background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
    border: 1px solid #e8eaed;
    border-radius: 14px;
    padding: 16px 18px;
    font-size: 13px;
    line-height: 1.7;
    color: #334155;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.03),
        0 1px 3px rgba(0, 0, 0, 0.02);
    animation: msgIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-result-box:hover {
    box-shadow:
        0 6px 20px rgba(0, 0, 0, 0.05),
        0 2px 6px rgba(0, 0, 0, 0.03);
}
.ai-result-box pre {
    background: #f4f6f9;
    border: 1px solid #e2e6ec;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    font-size: 12px;
    margin: 10px 0;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
}
.ai-result-box code {
    background: #eef1f5;
    border-radius: 5px;
    padding: 2px 7px;
    font-size: 12px;
    color: #c93546;
    font-weight: 500;
}

.ai-thinking {
    color: #a0a8b8;
    font-style: italic;
    font-size: 12px;
    padding: 4px 0;
}
