/* ===== 变量 ===== */
:root {
    --bg-primary: #f7f7f8;
    --bg-sidebar: #ffffff;
    --bg-message-user: #ff8c42;
    --bg-message-ai: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #6b6b6b;
    --accent: #ff6b35;
    --accent-hover: #e55a2b;
    --border: #e5e5e5;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
    --danger: #e53e3e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
}

.app-container { display: flex; height: 100vh; }

/* ===== 侧边栏 ===== */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 50;
}

.sidebar.collapsed { transform: translateX(-260px); }

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); }

.logo { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.logo-icon { font-size: 28px; }
.logo-text { font-size: 20px; font-weight: 700; color: var(--accent); }

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.2s;
}

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

/* ===== 对话历史列表 ===== */
.chat-history { flex: 1; overflow-y: auto; padding: 8px; }

.history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    position: relative;
}

.history-item:hover { background: var(--bg-primary); }

.history-item.active { background: #fff0eb; color: var(--accent); }

.history-item-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-item-delete {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
}

.history-item:hover .history-item-delete { display: block; }
.history-item-delete:hover { color: var(--danger); background: rgba(229,62,62,0.1); }

/* 侧边栏底部 */
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

.footer-btn {
    width: 100%;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.footer-btn:hover { background: rgba(229,62,62,0.1); color: var(--danger); }

/* 遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3);
    z-index: 40;
}

.sidebar-overlay.active { display: block; }

/* ===== 主聊天区 ===== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    display: none;
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.icon-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.icon-btn:hover { background: var(--bg-primary); }

/* ===== 欢迎页 ===== */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-content { text-align: center; max-width: 600px; padding: 20px; }
.welcome-logo { font-size: 64px; margin-bottom: 16px; }
.welcome-content h2 { font-size: 28px; margin-bottom: 8px; }
.welcome-content p { color: var(--text-secondary); margin-bottom: 32px; }

.suggestions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.suggestion-card {
    padding: 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.suggestion-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.suggestion-icon { font-size: 20px; }

/* ===== 消息区 ===== */
.messages-container { flex: 1; overflow-y: auto; padding: 20px 0; display: none; }
.messages-container.active { display: block; }
.welcome-screen.hidden { display: none; }

.message {
    max-width: 800px;
    margin: 0 auto 16px;
    padding: 0 20px;
    display: flex;
    gap: 12px;
    position: relative;
}

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

.message.user .message-avatar { background: #ffe0cc; }
.message.ai .message-avatar { background: #fff0eb; }

.message-content { flex: 1; min-width: 0; }

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-bubble {
    background: var(--bg-message-user);
    color: white;
    display: inline-block;
    max-width: 100%;
}

.message.ai .message-bubble {
    background: var(--bg-message-ai);
    border: 1px solid var(--border);
}

/* Markdown */
.message-bubble code { background: rgba(0,0,0,0.08); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.message.user .message-bubble code { background: rgba(255,255,255,0.25); }
.message-bubble pre { background: #1e1e1e; color: #d4d4d4; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.message-bubble pre code { background: none; padding: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin: 8px 0; }

/* 消息操作按钮 */
.msg-actions {
    display: none;
    position: absolute;
    top: -8px;
    right: 20px;
    gap: 4px;
    z-index: 5;
}

.message:hover .msg-actions { display: flex; }

.msg-action-btn {
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.msg-action-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 打字指示器 */
.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.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; }
}

/* ===== 输入区 ===== */
.input-area { padding: 12px 20px 20px; background: var(--bg-primary); }

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow);
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    font-family: inherit;
    max-height: 200px;
    padding: 8px;
    line-height: 1.5;
}

.send-btn, .stop-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.stop-btn { background: var(--danger); }
.stop-btn:hover { background: #c53030; }

.input-hint { text-align: center; font-size: 12px; color: var(--text-secondary); margin-top: 8px; }

/* ===== 弹窗 ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body { padding: 20px; }

.rename-input, .export-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
}

.export-textarea { min-height: 300px; resize: vertical; line-height: 1.6; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.btn-primary, .btn-secondary {
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    border: none;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-primary); color: var(--text-secondary); }

/* ===== 消息右键菜单 ===== */
.msg-menu {
    display: none;
    position: fixed;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 200;
    overflow: hidden;
}

.msg-menu.active { display: block; }

.msg-menu-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    color: var(--text-primary);
}

.msg-menu-item:hover { background: var(--bg-primary); }

/* ===== 空状态 ===== */
.empty-history {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 20px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100vh;
        transform: translateX(-260px);
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar-toggle { display: block; }
    .suggestions { grid-template-columns: 1fr; }
    .header-actions .icon-btn { font-size: 14px; padding: 4px 6px; }
}
