:root {
    --bg-color: #f7f7f7;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: #e0e0e0;
    --text-primary: #000000;
    --text-secondary: #666666;
    --accent-color: #000000;
    
    --message-user-bg: #000000;
    --message-user-text: #ffffff;
    --message-bot-bg: #ffffff;
    --message-bot-text: #000000;
    
    --sidebar-width: 280px;
    --radius-lg: 12px;
    --radius-md: 8px;
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color); color: var(--text-primary);
    height: 100vh; display: flex; overflow: hidden; -webkit-font-smoothing: antialiased;
}

/* 侧边栏及头部 */
.sidebar {
    width: var(--sidebar-width); background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border); display: flex; flex-direction: column;
    padding: 20px; z-index: 10;
}

.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.sidebar-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }

.icon-btn {
    background: transparent; border: none; cursor: pointer; width: 32px; height: 32px;
    border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.icon-btn:hover { background-color: #e0e0e0; transform: rotate(15deg); }
.icon-btn svg { width: 20px; height: 20px; fill: var(--text-primary); }

.new-chat-btn {
    background-color: var(--accent-color); color: white; border: 1px solid black;
    padding: 12px; border-radius: var(--radius-md); font-size: 15px; font-weight: 600;
    cursor: pointer; transition: var(--transition); margin-bottom: 20px; flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.new-chat-btn:hover { background-color: #333; transform: translateY(-2px); box-shadow: 0 6px 14px rgba(0,0,0,0.15); }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.chat-item {
    padding: 10px 30px 10px 12px; border-radius: var(--radius-md); cursor: pointer;
    transition: var(--transition); font-size: 14px; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; color: var(--text-secondary); border: 1px solid transparent; position: relative;
}
.chat-item::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%) scaleY(0);
    width: 3px; height: 60%; background: #000; border-radius: 0 4px 4px 0; transition: var(--transition);
}
.chat-item:hover { background-color: #eee; }
.chat-item.active { background-color: #fff; color: var(--accent-color); font-weight: 600; border-color: #ccc; box-shadow: 0 2px 4px rgba(0,0,0,0.02); }
.chat-item.active::before { transform: translateY(-50%) scaleY(1); }

.delete-chat-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: none;
    background: transparent; border: none; cursor: pointer; color: #999; padding: 4px;
}
.chat-item:hover .delete-chat-btn { display: block; }
.delete-chat-btn:hover { color: #d00; }
.delete-chat-btn svg { width: 14px; height: 14px; fill: currentColor; }

/* 设置区域 */
.settings-container {
    flex-shrink: 0; max-height: 0; overflow-y: hidden; display: flex; flex-direction: column; gap: 12px;
    opacity: 0; transition: max-height 0.5s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease, padding 0.3s ease;
    border-top: 1px solid transparent; padding-top: 0;
}
.settings-container.show { max-height: 550px; overflow-y: auto; opacity: 1; padding-top: 15px; border-top-color: var(--glass-border); }

.settings-group label { display: block; font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.settings-group input, .settings-group select, .settings-group textarea {
    width: 100%; padding: 8px 10px; border: 1px solid #ccc; border-radius: var(--radius-md); background: #fff; font-size: 13px; outline: none; transition: var(--transition); font-family: inherit;
}
.settings-group textarea { resize: vertical; min-height: 60px; }
.settings-group input:focus, .settings-group select:focus, .settings-group textarea:focus { border-color: #000; box-shadow: 0 0 0 1px #000; }

.btn-outline {
    width: 100%; padding: 8px; font-size: 12px; border: 1px solid #000; border-radius: var(--radius-md);
    background: transparent; cursor: pointer; transition: var(--transition); color: #000; font-weight: 600;
}
.btn-outline:hover { background: #000; color: #fff; }

.data-actions { display: flex; gap: 8px; margin-top: 5px; }
.data-actions button { flex: 1; padding: 8px; font-size: 12px; border: 1px solid #ccc; border-radius: var(--radius-md); background: white; cursor: pointer; transition: var(--transition); font-weight: 500; }
.data-actions button:hover { background: #eee; border-color: #999; }

/* 主聊天区域 */
.main-chat { flex: 1; display: flex; flex-direction: column; position: relative; }

.chat-header {
    display: flex; justify-content: space-between; align-items: center; padding: 16px 40px;
    background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border); z-index: 5;
}
.chat-header h3 { font-size: 16px; font-weight: 600; text-align: center; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 20px; }
.clear-chat-btn {
    background: transparent; border: 1px solid #ccc; padding: 6px 12px; border-radius: 6px; cursor: pointer;
    font-size: 12px; transition: var(--transition); display: flex; align-items: center; gap: 6px; font-weight: 500;
}
.clear-chat-btn:hover { background: #eee; border-color: #000; }
.clear-chat-btn svg { width: 14px; height: 14px; fill: currentColor; }

.chat-messages {
    flex: 1; padding: 40px; overflow-y: auto; scroll-behavior: smooth;
    display: flex; flex-direction: column; gap: 24px;
}

.message-wrapper { position: relative; display: flex; flex-direction: column; max-width: 80%; animation: slideUpFade 0.4s forwards; }
.message-wrapper.user { align-self: flex-end; align-items: flex-end; }
.message-wrapper.bot { align-self: flex-start; align-items: flex-start; }

.message { padding: 16px 20px; border-radius: var(--radius-lg); font-size: 15px; line-height: 1.6; word-wrap: break-word; width: 100%; }
@keyframes slideUpFade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.message.user { background-color: var(--message-user-bg); color: var(--message-user-text); border-bottom-right-radius: 4px; }
.message.bot { background-color: var(--message-bot-bg); color: var(--message-bot-text); border-bottom-left-radius: 4px; border: 1px solid var(--glass-border); box-shadow: 0 4px 12px rgba(0,0,0,0.03); }
.message img { max-width: 100%; border-radius: 8px; margin-bottom: 10px; border: 1px solid rgba(255,255,255,0.2); }

.message-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity 0.2s; }
.message-wrapper:hover .message-actions { opacity: 1; }
.action-icon {
    width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; border-radius: 4px; cursor: pointer; color: #888; transition: all 0.2s;
}
.action-icon:hover { background: #eee; border-color: #ddd; color: #000; }
.action-icon svg { width: 14px; height: 14px; fill: currentColor; }

.edit-area { width: 100%; min-width: 400px; min-height: 100px; padding: 12px; border: 1px solid #000; border-radius: var(--radius-md); font-family: inherit; font-size: 14px; resize: vertical; margin-bottom: 10px; outline: none; background: #fff; line-height: 1.5; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.edit-actions { display: flex; gap: 10px; justify-content: flex-end; width: 100%; }

/* Markdown */
.markdown-body { font-family: inherit; }
.markdown-body p { margin-bottom: 1em; } .markdown-body p:last-child { margin-bottom: 0; }
.markdown-body code { background-color: rgba(128,128,128,0.15); padding: 2px 4px; border-radius: 4px; font-family: monospace; font-size: 0.9em; }
.message.user .markdown-body code { background-color: rgba(255,255,255,0.2); }
.markdown-body pre { background-color: #1a1a1a; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 1em 0; border: 1px solid #333; }
.markdown-body pre code { background-color: transparent; padding: 0; color: #e5e5e5; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.markdown-body th, .markdown-body td { border: 1px solid #ddd; padding: 8px 12px; text-align: left; }
.message.user .markdown-body th, .message.user .markdown-body td { border-color: #444; }

.loading {
    align-self: flex-start; color: var(--text-secondary); font-size: 13px;
    padding: 10px 20px; display: none; font-style: italic; opacity: 0; animation: fadeIn 0.3s forwards;
}
@keyframes fadeIn { to { opacity: 1; } }
.loading span::after { content: '.'; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots { 0%, 20% { content: '.'; } 40% { content: '..'; } 60%, 100% { content: '...'; } }

/* 输入区域 */
.input-wrapper { background: var(--bg-color); border-top: 1px solid var(--glass-border); display: flex; flex-direction: column; }
.attachment-preview { display: none; padding: 15px 40px 0; gap: 10px; flex-wrap: wrap; align-items: center; }
.attachment-preview .img-wrap { position: relative; width: 60px; height: 60px; border-radius: 8px; border: 1px solid #ccc; overflow: hidden; animation: slideUpFade 0.3s forwards; }
.attachment-preview img { width: 100%; height: 100%; object-fit: cover; }
.attachment-preview .remove-btn { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.6); color: white; border: none; border-radius: 50%; width: 18px; height: 18px; font-size: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.input-area { padding: 20px 40px; display: flex; gap: 12px; align-items: flex-end; }
.upload-btn { background: transparent; border: 1px solid #ccc; width: 52px; height: 52px; border-radius: 26px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); flex-shrink: 0; }
.upload-btn:hover { background: #eee; border-color: #999; transform: translateY(-2px); }
.upload-btn svg { width: 22px; height: 22px; fill: #555; transition: var(--transition); }
.upload-btn:hover svg { fill: #000; }

.textarea-container {
    flex: 1; display: flex; align-items: stretch;
    border: 1px solid #ccc; border-radius: 24px; background: white;
    transition: var(--transition); overflow: hidden;
}
.textarea-container:focus-within {
    border-color: #000; box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.input-prefix-badge {
    display: none; background-color: #c4c4c4; color: white;
    padding: 0 16px; font-size: 14px; font-weight: 600;
    white-space: nowrap; align-items: center; justify-content: center;
    user-select: none; border-right: 1px solid #ccc;
}
.input-area textarea {
    flex: 1; padding: 14px 20px; border: none; font-size: 15px;
    font-family: inherit; resize: none; outline: none; background: transparent;
    height: 52px; max-height: 200px; line-height: 1.5;
}

.send-btn { background-color: var(--accent-color); color: white; border: none; width: 52px; height: 52px; border-radius: 26px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); flex-shrink: 0; }
.send-btn:hover { background-color: #333; transform: translateY(-2px) scale(1.02); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.send-btn:disabled { background-color: #ccc; cursor: not-allowed; transform: none; box-shadow: none; }
.send-btn svg { fill: white; width: 20px; height: 20px; margin-left: 2px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #999; }

/* --------- Toast 提示样式 --------- */
.toast-container {
    position: fixed; top: 24px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
    background: #fff; color: #000; border: 1px solid #ccc;
    padding: 12px 24px; border-radius: 30px; font-size: 14px; font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    animation: toastEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes toastEnter { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastLeave { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-20px); } }

/* --------- Modal 确认框样式 --------- */
.custom-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(255,255,255,0.7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000; opacity: 0; transition: opacity 0.3s ease;
}
.custom-modal {
    background: #fff; border: 1px solid #e0e0e0; border-radius: 16px;
    padding: 30px; width: 340px; text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    transform: scale(0.95); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.custom-modal-overlay.active { opacity: 1; }
.custom-modal-overlay.active .custom-modal { transform: scale(1); }
.custom-modal p { margin-bottom: 24px; font-size: 15px; font-weight: 500; color: #000; line-height: 1.5; }
.custom-modal-actions { display: flex; gap: 12px; }
.custom-modal-actions button {
    flex: 1; padding: 12px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.2s;
}
.custom-modal-btn-cancel { background: #fff; border: 1px solid #ccc; color: #333; }
.custom-modal-btn-cancel:hover { background: #f5f5f5; border-color: #999; }
.custom-modal-btn-confirm { background: #000; border: 1px solid #000; color: #fff; }
.custom-modal-btn-confirm:hover { background: #333; }