/* 贾维斯 v3.0 - AI 大脑浮动面板 */

/* 浮动按钮 */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
    transition: all var(--duration-normal);
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5);
}

.chat-fab.active {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
}

/* 未读提示点 */
.chat-fab-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger-color);
    border: 2px solid var(--bg-base);
    display: none;
}

.chat-fab-dot.show {
    display: block;
}

/* 对话面板 — iPhone Vibrancy */
.chat-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    width: 400px;
    height: 520px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--glass-filter);
    -webkit-backdrop-filter: var(--glass-filter);
    border-radius: var(--radius-xl);
    box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-highlight);
    display: flex;
    flex-direction: column;
    z-index: 899;
    overflow: hidden;
    animation: chatSlideUp 0.25s var(--ease-default);
}

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

/* 面板头部 */
.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.chat-panel-title-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
}

.chat-panel-actions {
    display: flex;
    gap: 4px;
}

.chat-panel-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

.chat-panel-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

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

/* 消息气泡 */
.chat-msg {
    max-width: 85%;
    animation: chatMsgIn 0.2s var(--ease-default);
}

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

.chat-msg-user {
    align-self: flex-end;
}

.chat-msg-assistant {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg-user .chat-msg-bubble {
    background: var(--accent-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant .chat-msg-bubble {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

/* 工具调用标签 */
.chat-tool-call {
    margin-top: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--accent-bg);
    border: 1px solid var(--accent-border);
    font-size: 11px;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 打字指示器 */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: chatTyping 1.4s infinite;
}

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

@keyframes chatTyping {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* 输入区域 */
.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    resize: none;
    max-height: 100px;
    transition: border-color var(--duration-fast);
}

.chat-input:focus {
    border-color: var(--accent-color);
}

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

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--accent-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--duration-fast);
}

.chat-send-btn:hover {
    background: var(--accent-hover-bg);
}

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

/* 欢迎消息 */
.chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: var(--text-tertiary);
}

.chat-welcome-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
}

.chat-welcome-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.chat-welcome-desc {
    font-size: var(--text-xs);
    line-height: 1.5;
}

.chat-welcome-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 12px;
}

.chat-hint-btn {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--duration-fast);
}

.chat-hint-btn:hover {
    background: var(--accent-bg);
    border-color: var(--accent-border);
    color: var(--accent-color);
}

/* 错误消息 */
.chat-msg-error .chat-msg-bubble {
    background: var(--danger-bg);
    color: var(--danger-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* 移动端适配 */
@media (max-width: 768px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }

    .chat-fab {
        bottom: 80px;
        right: 16px;
    }
}

/* ============ 决策#77 多模式 + 会话历史 + markdown 渲染 ============ */

/* 模式 tab */
.chat-mode-tabs {
    display: flex;
    gap: 2px;
    padding: 8px 12px 0;
    flex-shrink: 0;
}

.chat-mode-tab {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    border-bottom: 2px solid transparent;
    transition: all var(--duration-fast);
}

.chat-mode-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-surface);
}

.chat-mode-tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* 会话历史侧栏(左侧抽屉) */
.chat-sessions-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 100%;
    background: var(--bg-elevated);
    border-right: 1px solid var(--border-subtle);
    display: none;
    flex-direction: column;
    z-index: 10;
    animation: chatSlideLeft 0.2s var(--ease-default);
}

.chat-sessions-panel.show {
    display: flex;
}

@keyframes chatSlideLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

.chat-sessions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-primary);
}

.chat-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.chat-session-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: all var(--duration-fast);
    margin-bottom: 2px;
}

.chat-session-item:hover {
    background: var(--bg-surface);
}

.chat-session-item.active {
    background: var(--accent-bg);
    border-left-color: var(--accent-color);
}

.chat-session-title {
    flex: 1;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-session-item.active .chat-session-title {
    color: var(--accent-color);
    font-weight: 500;
}

.chat-session-mode {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--bg-surface);
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.chat-session-del {
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: 3px;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-session-item:hover .chat-session-del {
    display: flex;
}

.chat-session-del:hover {
    background: var(--danger-bg);
    color: var(--danger-color);
}

/* 数据来源/工具标签(单条字符串:fin.xxx / htsc.xxx/yyy) */
.chat-tool-call {
    margin-top: 6px;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    background: var(--accent-bg);
    border: 1px solid var(--accent-border);
    font-size: 10px;
    color: var(--accent-color);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    align-self: flex-start;
}

/* assistant 气泡 markdown 排版(覆盖默认 pre-wrap,支持 fin/htsc 返的表格) */
.chat-msg-assistant .chat-msg-bubble {
    white-space: normal;
}

.chat-msg-bubble.markdown-body p { margin: 0 0 8px; }
.chat-msg-bubble.markdown-body p:last-child { margin-bottom: 0; }

.chat-msg-bubble.markdown-body h1,
.chat-msg-bubble.markdown-body h2,
.chat-msg-bubble.markdown-body h3 {
    margin: 10px 0 6px;
    font-weight: 600;
    color: var(--text-primary);
}
.chat-msg-bubble.markdown-body h1 { font-size: 15px; }
.chat-msg-bubble.markdown-body h2 { font-size: 14px; }
.chat-msg-bubble.markdown-body h3 { font-size: 13px; }

.chat-msg-bubble.markdown-body ul,
.chat-msg-bubble.markdown-body ol {
    margin: 6px 0;
    padding-left: 20px;
}
.chat-msg-bubble.markdown-body li { margin: 2px 0; }

.chat-msg-bubble.markdown-body code {
    background: var(--bg-elevated);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
    font-family: var(--font-mono, monospace);
}

.chat-msg-bubble.markdown-body pre {
    background: var(--bg-elevated);
    padding: 10px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 6px 0;
}
.chat-msg-bubble.markdown-body pre code {
    background: transparent;
    padding: 0;
}

.chat-msg-bubble.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 12px;
    display: block;
    overflow-x: auto;
}
.chat-msg-bubble.markdown-body th,
.chat-msg-bubble.markdown-body td {
    border: 1px solid var(--border-default);
    padding: 5px 8px;
    text-align: left;
}
.chat-msg-bubble.markdown-body th {
    background: var(--bg-elevated);
    font-weight: 600;
}

.chat-msg-bubble.markdown-body strong {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-msg-bubble.markdown-body blockquote {
    border-left: 3px solid var(--accent-color);
    padding-left: 10px;
    margin: 6px 0;
    color: var(--text-secondary);
}
