/* ==========================================================================
   AI 智能助手 - 核心容器
   ========================================================================== */
#ai-assistant {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    pointer-events: none;
}

/* 主布局嵌入逻辑 */
body {
    transition: padding-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.ai-sidebar-open {
    padding-right: 480px; /* 侧边栏宽度 */
}

/* 针对固定定位的导航栏进行同步偏移 */
body.ai-sidebar-open .navbar.sticky-top {
    right: 480px;
    left: 0;
    width: auto;
}

/* ==========================================================================
   1. 聊天窗口 (Main Sidebar Window)
   ========================================================================== */
.ai-assistant-window {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    max-width: 100vw;
    height: 100vh;
    background: #ffffff;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.02);
    display: none;
    flex-direction: column;
    z-index: 10000;
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
}

.ai-assistant-window.active {
    display: flex;
}

/* ==========================================================================
   2. 窗口头部 (Header Section)
   ========================================================================== */
.ai-window-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.ai-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

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

.ai-actions {
    display: flex;
    gap: 6px;
}

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

.ai-btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ==========================================================================
   3. 消息区域 (Chat Body & Messages)
   ========================================================================== */
.ai-window-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
}

.ai-window-body::-webkit-scrollbar {
    width: 4px;
}

.ai-window-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

/* 欢迎卡片 */
.ai-welcome-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    text-align: center;
    border: 1px solid rgba(102, 126, 234, 0.1);
}

.ai-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    font-size: 22px;
}

.ai-welcome-title {
    font-weight: 600;
    font-size: 16px;
    margin-bottom: 6px;
}

.ai-welcome-desc {
    font-size: 13px;
    color: #6c757d;
}

.ai-welcome-card.hidden {
    display: none;
}

/* 消息气泡 */
.ai-message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-content {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

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

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

/* ==========================================================================
   4. 底部面板 (Footer, Quick Actions & Input)
   ========================================================================== */
.ai-window-footer {
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

/* 快捷提示词（单独一行） */
.ai-quick-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 16px 0;
    background: #ffffff;
    border-top: 1px solid #eee;
}

.ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.ai-quick-btn {
    padding: 6px 12px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-quick-btn:hover {
    background: #e9ecef;
}

/* Cursor Composer 风格：单框 + 底栏内置模式与操作 */
.ai-input-area {
    padding: 10px 16px 14px;
    background: #ffffff;
}

.ai-composer {
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.ai-composer:focus-within {
    box-shadow: 0 0 0 1px rgba(102, 126, 234, 0.35), 0 2px 12px rgba(102, 126, 234, 0.12);
}

.ai-composer-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: none;
    outline: none;
    padding: 12px 14px 8px;
    font-size: 14px;
    line-height: 1.45;
    color: #1a1a1a;
    background: transparent;
    font-family: inherit;
    min-height: 3.6em;
    resize: vertical;
    max-height: 200px;
}

.ai-composer-input::placeholder {
    color: #b0b0b0;
}

.ai-composer-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    min-height: 36px;
}

.ai-composer-toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

/* Chat / Tools 分段点选（内嵌底栏） */
.ai-composer-seg {
    display: inline-flex;
    padding: 2px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    flex-shrink: 0;
}

.ai-composer-seg-btn {
    border: none;
    background: transparent;
    padding: 4px 11px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #6b6b6b;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.25;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.ai-composer-seg-btn:hover:not(.active) {
    color: #333;
}

.ai-composer-seg-btn.active {
    background: #fff;
    color: #1a1a1a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.ai-composer-seg-btn:focus-visible {
    outline: 2px solid rgba(102, 126, 234, 0.45);
    outline-offset: 1px;
}

.ai-composer-model {
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 11rem;
    margin-left: 2px;
}

.ai-composer-toolbar-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ai-composer-send {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    font-size: 13px;
    transition: transform 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.ai-composer-send:hover:not(:disabled) {
    transform: scale(1.06);
}

.ai-composer-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

/* 清空对话确认弹层 */
.ai-modal-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.ai-modal-overlay.is-open {
    display: flex;
}

.ai-modal-dialog {
    width: 100%;
    max-width: 320px;
    background: #fff;
    border-radius: 14px;
    padding: 20px 20px 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.06);
    animation: aiModalIn 0.2s ease;
}

@keyframes aiModalIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(6px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.ai-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: #111827;
    margin: 0 0 8px;
}

.ai-modal-desc {
    font-size: 13px;
    line-height: 1.5;
    color: #6b7280;
    margin: 0 0 18px;
}

.ai-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.ai-modal-btn {
    border: none;
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-modal-btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.ai-modal-btn-secondary:hover {
    background: #e5e7eb;
}

.ai-modal-btn-danger {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.ai-modal-btn-danger:hover {
    filter: brightness(1.05);
}

/* 动画与加载状态 (Animations) */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-4px); }
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

/* 加载动画 */
.ai-loading {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #667eea;
    animation: bounce 1.4s infinite;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ==========================================================================
   6. 响应式布局 (Mobile Responsive)
   ========================================================================== */
@media (max-width: 768px) {
    body.ai-sidebar-open {
        padding-right: 0;
    }
    body.ai-sidebar-open .navbar.sticky-top {
        width: 100%;
    }
    .ai-assistant-window {
        width: 100vw;
        height: 100vh;
        border-left: none;
    }
}
