/* ============================================================
   AI电商客服系统 - 主样式文件
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f3f4f6;
    --sidebar-bg: #1e1e2e;
    --sidebar-text: #cdd6f4;
    --sidebar-hover: #313244;
    --sidebar-active: #45475a;
    --white: #ffffff;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-light: #6b7280;
    --user-bubble: #4f46e5;
    --ai-bubble: #ffffff;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ============ 布局 ============ */
.app-container {
    display: flex;
    height: 100vh;
}

/* ============ 侧边栏 ============ */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s;
}
.sidebar.hidden { margin-left: -280px; }

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-hover);
}
.sidebar-header h2 { font-size: 18px; }

.btn-new-chat {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}
.btn-new-chat:hover { background: var(--primary-hover); }

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 14px;
    transition: background 0.15s;
}
.session-item:hover { background: var(--sidebar-hover); }
.session-item.active { background: var(--sidebar-active); }
.session-item .session-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.session-item .btn-delete-session {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    opacity: 0;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity 0.15s;
}
.session-item:hover .btn-delete-session { opacity: 0.6; }
.session-item .btn-delete-session:hover { opacity: 1; color: var(--danger); }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-hover);
}
.btn-settings {
    background: none;
    border: 1px solid var(--sidebar-hover);
    color: var(--sidebar-text);
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}
.btn-settings:hover { background: var(--sidebar-hover); }

/* ============ 聊天主区 ============ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 12px 20px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-toggle-sidebar {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px 8px;
    border-radius: 6px;
}
.btn-toggle-sidebar:hover { background: var(--bg); }
.chat-header h3 { flex: 1; font-size: 16px; font-weight: 600; }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-light);
    display: inline-block;
}
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }

/* ============ 消息区 ============ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}
.welcome-icon { font-size: 48px; margin-bottom: 16px; }
.welcome-message h3 { margin-bottom: 8px; color: var(--text); }
.welcome-message p { margin-bottom: 24px; }
.welcome-message a { color: var(--primary); cursor: pointer; }

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}
.quick-btn {
    background: var(--white);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: all 0.15s;
}
.quick-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

/* 消息气泡 */
.message-row {
    display: flex;
    gap: 10px;
    max-width: 80%;
    animation: fadeIn 0.3s;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.message-row.user { align-self: flex-end; flex-direction: row-reverse; }
.message-row.assistant { align-self: flex-start; }

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.message-row.user .message-avatar { background: var(--primary); color: #fff; font-size: 14px; }
.message-row.assistant .message-avatar { background: #e0e7ff; }

.message-bubble {
    padding: 10px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 14px;
    word-break: break-word;
    white-space: pre-wrap;
}
.message-row.user .message-bubble {
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message-row.assistant .message-bubble {
    background: var(--ai-bubble);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }

/* 加载动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%,80%,100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.error-message {
    background: #fef2f2;
    color: var(--danger);
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid #fecaca;
    align-self: center;
    max-width: 80%;
}

/* ============ 输入区 ============ */
.chat-input-area {
    padding: 12px 20px 16px;
    background: var(--white);
    border-top: 1px solid var(--border);
}
.input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
#messageInput {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: border-color 0.15s;
    line-height: 1.5;
}
#messageInput:focus { border-color: var(--primary); }

.btn-send {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn-send:hover { background: var(--primary-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

.input-hint {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
    text-align: right;
}

/* ============ 设置弹窗 ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: var(--white);
    border-radius: 16px;
    width: 640px;
    max-width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 16px; }
.btn-close-modal {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-light);
    padding: 4px 8px;
    border-radius: 6px;
}
.btn-close-modal:hover { background: var(--bg); }

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* Tabs */
.settings-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.tab-btn {
    background: none;
    border: none;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-light);
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 表单 */
.form-group {
    margin-bottom: 14px;
}
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}
.required { color: var(--danger); }
.form-group input,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-light);
}

.input-with-btn {
    display: flex;
    gap: 6px;
}
.input-with-btn input { flex: 1; }
.btn-sm {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.btn-sm:hover { background: var(--border); }

.form-row {
    display: flex;
    gap: 12px;
}
.form-row .form-group { flex: 1; }

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
}
.btn-secondary:hover { background: var(--bg); }

.test-result {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    display: none;
}
.test-result.success { display: block; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.test-result.error { display: block; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* 业务配置 */
.biz-config-scroll {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}
.biz-config-scroll .form-group textarea {
    min-height: 36px;
    resize: vertical;
}

/* Prompt预览 */
.prompt-preview-actions { margin-bottom: 12px; }
.prompt-preview {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    font-size: 12px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "Consolas", "Monaco", monospace;
}

/* ============ Toast提示 ============ */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    color: #fff;
    z-index: 2000;
    animation: slideIn 0.3s, fadeOut 0.3s 2.7s;
    pointer-events: none;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============ 滚动条 ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
    .sidebar { position: fixed; z-index: 100; height: 100vh; }
    .sidebar.hidden { margin-left: -280px; }
    .message-row { max-width: 90%; }
    .modal-content { width: 100vw; max-width: 100vw; border-radius: 12px 12px 0 0; max-height: 90vh; }
}
