/* ========== AI 智能助手 ========== */

/* 悬浮触发按钮 */
.ai-fab {
    position: fixed;
    right: 28px;
    bottom: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
    z-index: 9998;
    transition: all 0.3s ease;
    border: none;
}

.ai-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}

.ai-fab svg {
    width: 26px;
    height: 26px;
}

.ai-fab .pulse-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--primary);
    animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* 助手面板 */
.ai-panel {
    position: fixed;
    right: 28px;
    bottom: 28px;
    width: 420px;
    height: 640px;
    max-height: calc(100vh - 56px);
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* 头部 */
.ai-panel-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-panel-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-avatar svg {
    width: 22px;
    height: 22px;
}

.ai-panel-title {
    font-size: 16px;
    font-weight: 600;
}

.ai-panel-subtitle {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ADE80;
    display: inline-block;
}

.ai-panel-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-panel-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 快捷问题 */
.ai-quick-questions {
    padding: 12px 16px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.ai-quick-btn {
    padding: 6px 14px;
    border-radius: 16px;
    background: var(--bg-body);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.ai-quick-btn:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}

/* 消息列表 */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-msg {
    display: flex;
    gap: 10px;
    max-width: 100%;
}

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

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

.ai-msg.ai .ai-msg-avatar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--info) 100%);
    color: white;
}

.ai-msg.user .ai-msg-avatar {
    background: var(--bg-body);
    color: var(--text-secondary);
}

.ai-msg-content {
    background: var(--bg-body);
    border-radius: 12px 12px 12px 4px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    word-break: break-word;
}

.ai-msg.user .ai-msg-content {
    background: var(--primary);
    color: white;
    border-radius: 12px 12px 4px 12px;
    margin-right: 4px;
}

.ai-msg.ai .ai-msg-content {
    margin-left: 4px;
}

/* Markdown 渲染 */
.ai-msg-content h1,
.ai-msg-content h2,
.ai-msg-content h3 {
    margin: 8px 0 4px;
    font-size: 15px;
    font-weight: 600;
}

.ai-msg-content h1 { font-size: 16px; }
.ai-msg-content h2 { font-size: 15px; }
.ai-msg-content h3 { font-size: 14px; }

.ai-msg-content p {
    margin: 4px 0;
}

.ai-msg-content ul,
.ai-msg-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.ai-msg-content li {
    margin: 2px 0;
}

.ai-msg-content strong {
    font-weight: 600;
}

.ai-msg-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.ai-msg.user .ai-msg-content code {
    background: rgba(255, 255, 255, 0.2);
}

.ai-msg-content pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}

.ai-msg-content pre code {
    background: none;
    padding: 0;
}

/* 打字指示器 */
.ai-typing {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.4s infinite;
}

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

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

/* 输入区 */
.ai-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--bg-card);
}

.ai-input {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 42px;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.2s;
}

.ai-input:focus {
    outline: none;
    border-color: var(--primary);
}

.ai-send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.ai-send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

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

/* AI 处理中遮罩 */
.ai-processing-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 9997;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-processing-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-lg);
    min-width: 320px;
}

.ai-processing-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-processing-text {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

.ai-processing-subtext {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* 响应式 */
@media (max-width: 768px) {
    .ai-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        right: 8px;
        bottom: 8px;
    }

    .ai-fab {
        right: 16px;
        bottom: 16px;
    }
}
