/* ── 基础变量 ─────────────────────────────────────────── */
:root {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-bg: #EEF2FF;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-500: #6B7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; color: var(--gray-900); }
.hidden { display: none !important; }

/* ── 登录/注册页 ──────────────────────────────────────── */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}
.auth-container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.auth-header { text-align: center; margin-bottom: 30px; }
.auth-header .logo { font-size: 48px; margin-bottom: 10px; }
.auth-header h1 { font-size: 28px; color: var(--primary); }
.auth-header .subtitle { color: var(--gray-500); font-size: 14px; margin-top: 6px; }

.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border-radius: 10px; overflow: hidden; border: 2px solid var(--primary); }
.tab-btn { flex: 1; padding: 10px; border: none; background: white; color: var(--primary); font-size: 15px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.tab-btn.active { background: var(--primary); color: white; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.form-group input, .form-group select {
    width: 100%; padding: 12px 14px; border: 2px solid var(--gray-200);
    border-radius: 10px; font-size: 15px; transition: border-color 0.2s;
    outline: none; background: white;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.password-field { position: relative !important; width: 100%; display: block; }
.password-field input {
    width: 100%;
    padding-right: 48px !important;
    box-shadow: 0 1px 2px rgba(15,23,42,0.04);
}
.password-toggle {
    position: absolute !important; right: 10px; top: 50%; transform: translateY(-50%);
    width: 30px; height: 30px; border: none; border-radius: 999px;
    background: var(--gray-50); color: var(--gray-500); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; padding: 0; z-index: 2;
}
.password-toggle svg { width: 18px; height: 18px; stroke-width: 2; }
.password-toggle:hover { color: var(--primary); background: var(--primary-bg); box-shadow: 0 2px 8px rgba(79,70,229,0.14); }
.password-toggle:active { transform: translateY(-50%) scale(0.92); }

/* 隐藏浏览器自带的密码显示按钮 */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }
input[type="password"]::-webkit-credentials-auto-fill-button { display: none; }

.btn-primary {
    width: 100%; padding: 14px; background: var(--primary); color: white;
    border: none; border-radius: 10px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: background 0.2s; margin-top: 8px;
}
.btn-primary:hover { background: #4338CA; }
.btn-primary:disabled { background: var(--gray-300); cursor: not-allowed; }

.msg { text-align: center; margin-top: 12px; font-size: 14px; }
.msg.error { color: var(--danger); }
.msg.success { color: var(--success); }

/* ── 对话页 ──────────────────────────────────────────── */
.chat-body { display: flex; flex-direction: column; height: 100vh; background: var(--gray-50); }

.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 20px; background: white; border-bottom: 1px solid var(--gray-200);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left .logo-sm { font-size: 24px; }
.header-left h2 { font-size: 18px; color: var(--primary); }
.header-right { display: flex; align-items: center; gap: 10px; }
.user-badge { font-size: 13px; color: var(--gray-500); background: var(--gray-100); padding: 4px 12px; border-radius: 20px; }

.btn-sm { padding: 6px 14px; border: none; border-radius: 8px; font-size: 13px; cursor: pointer; background: var(--primary-bg); color: var(--primary); font-weight: 500; transition: all 0.2s; }
.btn-sm:hover { background: var(--primary); color: white; }
.btn-outline { background: white; border: 1px solid var(--gray-300); color: var(--gray-500); }
.btn-outline:hover { background: var(--gray-100); color: var(--danger); border-color: var(--danger); }

/* 消息区域 */
.chat-main { flex: 1; overflow-y: auto; padding: 20px; }
.messages { max-width: 800px; margin: 0 auto; }

.welcome-card {
    text-align: center; padding: 40px 20px; background: white;
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.welcome-card .welcome-icon { font-size: 56px; margin-bottom: 16px; }
.welcome-card h3 { font-size: 22px; color: var(--primary); margin-bottom: 10px; }
.welcome-card p { color: var(--gray-500); font-size: 15px; line-height: 1.6; margin-bottom: 24px; }

.quick-starts { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.quick-starts button {
    padding: 10px 16px; border: 2px solid var(--gray-200); border-radius: 20px;
    background: white; font-size: 14px; cursor: pointer; transition: all 0.2s;
    color: var(--gray-700);
}
.quick-starts button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* 消息气泡 */
.message { display: flex; gap: 12px; margin-bottom: 20px; animation: fadeIn 0.3s ease; }
.message.user { flex-direction: row-reverse; }
.message .avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.message.assistant .avatar { background: var(--primary-bg); }
.message.user .avatar { background: #DBEAFE; }
.message .bubble {
    max-width: 75%; padding: 14px 18px; border-radius: 16px;
    font-size: 15px; line-height: 1.7; word-break: break-word;
}
.message.assistant .bubble { background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-top-left-radius: 4px; }
.message.user .bubble { background: var(--primary); color: white; border-top-right-radius: 4px; }
.message .bubble h1, .message .bubble h2, .message .bubble h3 { margin: 12px 0 6px; }
.message .bubble ul, .message .bubble ol { padding-left: 20px; margin: 8px 0; }
.message .bubble li { margin: 4px 0; }
.message .bubble strong { color: var(--primary); }
.message.user .bubble strong { color: #C7D2FE; }
.message .bubble blockquote { border-left: 3px solid var(--primary-light); padding-left: 12px; margin: 8px 0; color: var(--gray-700); }

/* 工具调用提示 */
.tool-indicator {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 12px; background: var(--primary-bg); border-radius: 12px;
    font-size: 12px; color: var(--primary); margin: 4px 0;
}
.tool-indicator .spinner {
    width: 12px; height: 12px; border: 2px solid var(--primary-light);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* 打字指示器 */
.typing-indicator { display: flex; gap: 4px; padding: 8px 0; }
.typing-indicator span {
    width: 8px; height: 8px; background: var(--gray-300); border-radius: 50%;
    animation: bounce 1.4s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

/* 输入区域 */
.chat-footer { padding: 16px 20px; background: white; border-top: 1px solid var(--gray-200); }
.input-area {
    max-width: 800px; margin: 0 auto; display: flex; gap: 12px;
    align-items: flex-end; background: var(--gray-50); border-radius: 16px;
    padding: 8px 8px 8px 16px; border: 2px solid var(--gray-200);
    transition: border-color 0.2s;
}
.input-area:focus-within { border-color: var(--primary); }
.input-area textarea {
    flex: 1; border: none; outline: none; background: transparent;
    font-size: 15px; line-height: 1.5; resize: none; min-height: 24px;
    max-height: 120px; font-family: inherit;
}
.btn-send {
    width: 40px; height: 40px; border: none; border-radius: 10px;
    background: var(--primary); color: white; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s; flex-shrink: 0;
}
.btn-send:hover { background: #4338CA; }
.btn-send:disabled { background: var(--gray-300); cursor: not-allowed; }

/* 数据面板 */
.data-panel {
    position: fixed; top: 0; right: 0; width: 380px; height: 100vh;
    background: white; box-shadow: -4px 0 24px rgba(0,0,0,0.1);
    z-index: 100; display: flex; flex-direction: column;
    animation: slideIn 0.3s ease;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px; border-bottom: 1px solid var(--gray-200);
}
.panel-header h3 { font-size: 18px; }
.btn-close { width: 32px; height: 32px; border: none; background: var(--gray-100); border-radius: 50%; font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

.panel-body { padding: 20px; flex: 1; overflow-y: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; }
.stat-card { text-align: center; padding: 16px; background: var(--gray-50); border-radius: 12px; }
.stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* 历史对话列表 */
.history-section { margin-top: 8px; }
.history-section h4 { font-size: 14px; color: var(--gray-700); margin-bottom: 12px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
    padding: 12px 14px; background: var(--gray-50); border-radius: 10px;
    border: 1px solid var(--gray-100); cursor: default;
}
.history-item .hi-time { font-size: 11px; color: var(--gray-500); margin-bottom: 4px; }
.history-item .hi-input { font-size: 13px; color: var(--gray-900); margin-bottom: 4px; font-weight: 500; }
.history-item .hi-reply { font-size: 12px; color: var(--gray-500); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-item .hi-stage { display: inline-block; font-size: 11px; background: var(--primary-bg); color: var(--primary); padding: 1px 8px; border-radius: 8px; margin-left: 6px; }

/* 修改密码弹窗 */
.pwd-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 200;
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn 0.2s ease;
}
.pwd-modal {
    background: white; border-radius: var(--radius); padding: 28px;
    width: 400px; max-width: 90vw; box-shadow: 0 8px 40px rgba(0,0,0,0.15);
}
.pwd-modal h3 { font-size: 18px; margin-bottom: 20px; color: var(--gray-900); }
.pwd-modal .form-group { margin-bottom: 14px; }
.pwd-modal .form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.pwd-modal .form-group input {
    width: 100%; padding: 10px 14px; border: 2px solid var(--gray-200);
    border-radius: 10px; font-size: 14px; outline: none; transition: border-color 0.2s;
}
.pwd-modal .form-group input:focus { border-color: var(--primary); }
.pwd-modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.pwd-modal-btns .btn-cancel {
    padding: 10px 20px; border: 1px solid var(--gray-300); border-radius: 8px;
    background: white; font-size: 14px; cursor: pointer; color: var(--gray-500);
}
.pwd-modal-btns .btn-confirm {
    padding: 10px 20px; border: none; border-radius: 8px;
    background: var(--primary); color: white; font-size: 14px; font-weight: 600; cursor: pointer;
}
.pwd-modal-btns .btn-confirm:hover { background: #4338CA; }
.pwd-msg { font-size: 13px; margin-top: 10px; text-align: center; }
.pwd-msg.error { color: var(--danger); }
.pwd-msg.success { color: var(--success); }

/* ── 动画 ────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

/* ── 响应式 ──────────────────────────────────────────── */
@media (max-width: 640px) {
    .auth-container { padding: 24px; }
    .message .bubble { max-width: 85%; }
    .data-panel { width: 100%; }
    .quick-starts { flex-direction: column; }
    .quick-starts button { width: 100%; }
}

/* ── 工具调用和错误样式 ─────────────────────────────── */
.tool-call {
    display: inline-block;
    background: #EEF2FF;
    color: #4F46E5;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    margin: 4px 0;
}
.error {
    color: #EF4444;
    font-style: italic;
}
