/* ==================== AI Assistant 侧边栏样式 ==================== */

/* AI助手触发按钮 */
.ai-assistant-btn {
    position: fixed;
    top: 30px;
    right: 120px;
    z-index: 1000;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.ai-assistant-btn:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
}

.ai-assistant-btn:hover svg {
    fill: white;
}

.ai-assistant-btn svg {
    width: 22px;
    height: 22px;
    fill: var(--text-primary);
    transition: fill 0.3s ease;
}

.ai-assistant-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
}

.ai-assistant-btn.active svg {
    fill: white;
}

/* AI助手侧边栏遮罩 */
.ai-assistant-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-assistant-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* AI助手侧边栏面板 */
.ai-assistant-panel {
    position: fixed;
    top: 0;
    right: -450px;
    width: 450px;
    min-width: 320px;
    max-width: 80vw;
    height: 100vh;
    background-color: var(--bg-color);
    border-left: 1px solid var(--border-color);
    z-index: 1002;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-assistant-panel.active {
    right: 0;
}

/* 拖拽调整大小的手柄 */
.ai-assistant-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background-color 0.2s ease;
}

.ai-assistant-resize-handle:hover,
.ai-assistant-resize-handle.resizing {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* 面板头部 */
.ai-assistant-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
}

.ai-assistant-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.ai-assistant-title svg {
    width: 20px;
    height: 20px;
    fill: #667eea;
}

.ai-assistant-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-assistant-close:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

.ai-assistant-close svg {
    width: 20px;
    height: 20px;
}

/* 聊天内容区域 */
.ai-assistant-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 消息样式 */
.ai-message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.ai-message-avatar.ai {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-message-avatar.user {
    background-color: var(--text-primary);
    color: var(--bg-color);
}

.ai-message-bubble {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    max-width: calc(100% - 44px);
}

.ai-message.ai .ai-message-bubble {
    background-color: var(--hover-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.ai-message.user .ai-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.ai-message.user {
    flex-direction: row-reverse;
}

/* 加载动画 */
.ai-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.ai-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    animation: typing 1.4s infinite ease-in-out;
}

.ai-typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* 页面内容摘要卡片 */
.ai-summary-card {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border: 1px solid rgba(102, 126, 234, 0.2);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
}

.ai-summary-card h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-summary-card h4 svg {
    width: 16px;
    height: 16px;
    fill: #667eea;
}

.ai-summary-card p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* 快捷问题按钮 */
.ai-quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.ai-quick-btn {
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: var(--bg-color);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-quick-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
}

/* 输入区域 */
.ai-assistant-input-area {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-color);
    flex-shrink: 0;
}

.ai-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.ai-input-wrapper {
    flex: 1;
    position: relative;
}

.ai-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 14px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    font-family: inherit;
}

.ai-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-input::placeholder {
    color: var(--text-tertiary);
}

.ai-send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ai-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-send-btn svg {
    width: 20px;
    height: 20px;
}

/* 连接状态指示器 */
.ai-connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 8px 0;
}

.ai-connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #22c55e;
    animation: pulse 2s ease-in-out infinite;
}

.ai-connection-dot.disconnected {
    background-color: #ef4444;
    animation: none;
}

.ai-connection-dot.connecting {
    background-color: #f59e0b;
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* 设置面板 */
.ai-settings-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-settings-toggle:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

.ai-settings-toggle svg {
    width: 18px;
    height: 18px;
}

.ai-settings-panel {
    display: none;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--hover-bg);
}

.ai-settings-panel.active {
    display: block;
}

.ai-settings-item {
    margin-bottom: 12px;
}

.ai-settings-item:last-child {
    margin-bottom: 0;
}

.ai-settings-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.ai-settings-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    background-color: var(--bg-color);
    color: var(--text-primary);
    outline: none;
}

.ai-settings-input:focus {
    border-color: #667eea;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-assistant-btn {
        top: 20px;
        right: 80px;
        width: 40px;
        height: 40px;
    }

    .ai-assistant-btn svg {
        width: 18px;
        height: 18px;
    }

    .ai-assistant-panel {
        width: 100%;
        max-width: 100%;
        right: -100%;
    }

    .ai-assistant-panel.active {
        right: 0;
    }

    .ai-assistant-resize-handle {
        display: none;
    }

    .ai-assistant-header {
        padding: 16px;
    }

    .ai-assistant-content {
        padding: 16px;
    }

    .ai-assistant-input-area {
        padding: 12px 16px;
    }
}

@media (max-width: 480px) {
    .ai-assistant-btn {
        top: 16px;
        right: 70px;
        width: 36px;
        height: 36px;
    }

    .ai-assistant-btn svg {
        width: 16px;
        height: 16px;
    }

    .ai-message-bubble {
        padding: 10px 14px;
        font-size: 13px;
    }

    .ai-input {
        padding: 10px 14px;
        font-size: 14px;
    }

    .ai-send-btn {
        width: 40px;
        height: 40px;
    }
}

/* 暗色模式适配 */
@media (prefers-color-scheme: dark) {
    .ai-assistant-panel {
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .ai-assistant-overlay {
        background-color: rgba(0, 0, 0, 0.5);
    }

    .ai-summary-card {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
        border-color: rgba(102, 126, 234, 0.3);
    }
}

/* Markdown 内容样式 */
.ai-message-bubble code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
}

.ai-message-bubble pre {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-message-bubble pre code {
    background: none;
    padding: 0;
}

.ai-message-bubble ul,
.ai-message-bubble ol {
    padding-left: 20px;
    margin: 8px 0;
}

.ai-message-bubble li {
    margin-bottom: 4px;
}

.ai-message-bubble strong {
    font-weight: 600;
}

.ai-message-bubble em {
    font-style: italic;
}

/* 用户消息中的代码样式 */
.ai-message.user .ai-message-bubble code {
    background-color: rgba(255, 255, 255, 0.2);
}

.ai-message.user .ai-message-bubble pre {
    background-color: rgba(255, 255, 255, 0.1);
}
