/* TalkBreed 对话式 UI（v3.0 现代化重构）*/
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #d1fae5;
    --bg: #f7f8fa;
    --surface: #ffffff;
    --text: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --user-bubble: #10b981;
    --radius: 14px;
    /* 来源徽章 */
    --badge-local-bg:#ecfdf5; --badge-local-fg:#047857; --badge-local-bd:#a7f3d0;
    --badge-ncbi-bg:#eff6ff;  --badge-ncbi-fg:#1d4ed8;  --badge-ncbi-bd:#bfdbfe;
    --badge-brapi-bg:#f5f3ff; --badge-brapi-fg:#6d28d9; --badge-brapi-bd:#ddd6fe;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    font-size: 15px;
}

.hidden { display: none !important; }
.app { display: flex; flex-direction: column; height: 100vh; }

/* ===== 顶栏 ===== */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 28px; }
.topbar-left h1 { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.tagline { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.topbar-right { display: flex; gap: 8px; }
.icon-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 7px 14px; cursor: pointer; font-size: 13px; color: var(--text);
    transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg); border-color: var(--primary); }
.icon-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-btn.primary:hover { background: var(--primary-dark); }

/* ===== 对话区 ===== */
.chat { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 28px 16px 8px; scroll-behavior: smooth; }
.messages > * { max-width: 800px; margin: 0 auto 18px; }

/* 欢迎屏 */
.welcome { text-align: center; padding: 56px 16px; }
.welcome-emoji { font-size: 52px; margin-bottom: 14px; }
.welcome h2 { font-size: 26px; margin-bottom: 10px; font-weight: 700; }
.welcome p { color: var(--text-muted); margin-bottom: 28px; line-height: 1.6; }
.suggest { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 560px; margin: 0 auto; }
.suggest button {
    padding: 11px 18px; border: 1px solid var(--border); background: var(--surface);
    border-radius: 22px; cursor: pointer; font-size: 13.5px; color: var(--text);
    transition: all 0.15s;
}
.suggest button:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* 追问 chips（AI 回答后） */
.followups {
    margin-top: 14px; padding-top: 12px;
    border-top: 1px dashed var(--border);
    display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.followups-label { width: 100%; font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.followup-chip {
    background: var(--bg); border: 1px solid var(--border); color: var(--text);
    border-radius: 16px; padding: 5px 12px; font-size: 13px; cursor: pointer;
    transition: all 0.15s;
}
.followup-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.suggest-group { width: 100%; font-size: 12px; color: var(--text-muted); margin: 6px 0 2px; text-align: left; }

/* ===== 更新日志（全屏覆盖）===== */
.changelog-overlay {
    position: fixed; inset: 0; z-index: 250;
    background: rgba(0,0,0,0.35);
    display: flex; justify-content: center;
    overflow-y: auto; padding: 40px 16px;
}
.changelog-inner {
    position: relative; align-self: flex-start;
    background: var(--surface); border-radius: 16px;
    max-width: 720px; width: 100%; padding: 36px 40px 28px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
}
.changelog-inner h2 { font-size: 22px; margin-bottom: 20px; }
.changelog-close {
    position: absolute; top: 14px; right: 16px;
    background: none; border: none; font-size: 20px; cursor: pointer;
    color: var(--text-muted); line-height: 1;
}
.changelog-close:hover { color: var(--text); }
.changelog-version { padding: 14px 0; border-top: 1px solid var(--border); }
.changelog-version:first-of-type { border-top: none; }
.changelog-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.changelog-ver { font-size: 16px; font-weight: 700; color: var(--primary); }
.changelog-date { font-size: 12px; color: var(--text-muted); }
.changelog-title { font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.changelog-items { margin: 6px 0 0 18px; font-size: 13.5px; line-height: 1.7; }
.changelog-items li { margin-bottom: 3px; }

/* ===== 消息 ===== */
.msg { display: flex; margin-bottom: 18px; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
    background: var(--user-bubble); color: #fff; padding: 11px 16px;
    border-radius: 16px 16px 4px 16px; max-width: 72%; line-height: 1.55; word-break: break-word;
}
.msg.assistant .ai-content {
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    padding: 18px 22px; width: 100%; line-height: 1.75; box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.ai-content h1 { font-size: 20px; margin: 14px 0 8px; }
.ai-content h2 { font-size: 17px; margin: 14px 0 6px; }
.ai-content h3 { font-size: 15px; margin: 12px 0 6px; }
.ai-content p { margin: 8px 0; }
.ai-content code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; font-family: 'SF Mono', Menlo, monospace; }
.ai-content pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; font-size: 13px; white-space: pre-wrap; }
.ai-content pre code { background: none; padding: 0; }
.ai-content table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13.5px; }
.ai-content td, .ai-content th { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.ai-content th { background: var(--bg); font-weight: 600; }
.ai-content ul, .ai-content ol { margin: 8px 0 8px 22px; }
.typing { color: var(--text-muted); }
.status { color: var(--primary); font-size: 14px; padding: 4px 0; }
.stream-section { background: var(--bg); border-radius: 10px; padding: 12px 14px; margin: 8px 0; font-size: 13.5px; }
.sec-title { font-weight: 600; margin-bottom: 6px; }
.error { color: #dc2626; }

/* 来源徽章 */
.source-badge {
    display: inline-block; padding: 2px 11px; border-radius: 12px;
    font-size: 0.85em; font-weight: 600; border: 1px solid; margin: 3px 4px 3px 0;
}
.source-badge-local  { background: var(--badge-local-bg);  color: var(--badge-local-fg);  border-color: var(--badge-local-bd); }
.source-badge-ncbi   { background: var(--badge-ncbi-bg);   color: var(--badge-ncbi-fg);   border-color: var(--badge-ncbi-bd); }
.source-badge-brapi  { background: var(--badge-brapi-bg);  color: var(--badge-brapi-fg);  border-color: var(--badge-brapi-bd); }

/* ===== 输入区 ===== */
.composer { background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px 10px; }
.composer-inner { max-width: 800px; margin: 0 auto; }
.source-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.source-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.source-select {
    flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); font-size: 14px; color: var(--text); cursor: pointer;
}
.source-select:focus { outline: none; border-color: var(--primary); }
.input-row {
    display: flex; gap: 10px; align-items: flex-end;
    border: 1px solid var(--border); border-radius: 16px; padding: 8px 8px 8px 14px; background: var(--bg);
    transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--primary); }
.input-row textarea {
    flex: 1; border: none; background: transparent; resize: none; outline: none;
    font-size: 15px; line-height: 1.5; padding: 6px 0; max-height: 140px; font-family: inherit; color: var(--text);
}
.send-btn {
    background: var(--primary); color: #fff; border: none; border-radius: 50%;
    width: 38px; height: 38px; cursor: pointer; font-size: 16px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hint { font-size: 11.5px; color: var(--text-muted); text-align: center; margin-top: 8px; }

/* ===== 历史侧栏 ===== */
.history-sidebar {
    position: fixed; right: 0; top: 0; width: 320px; height: 100vh;
    background: var(--surface); border-left: 1px solid var(--border);
    box-shadow: -4px 0 16px rgba(0,0,0,0.06);
    display: flex; flex-direction: column; z-index: 100;
}
.sidebar-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 15px; }
.history-list { flex: 1; overflow-y: auto; padding: 10px; }
.history-item {
    padding: 11px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 6px;
    font-size: 13.5px; line-height: 1.45; transition: background 0.12s;
}
.history-item:hover { background: var(--bg); }
.history-item .ts { color: var(--text-muted); font-size: 11px; margin-top: 4px; display: block; }
.btn-danger {
    margin: 12px; padding: 9px; border: 1px solid #fecaca; background: #fef2f2;
    color: #dc2626; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-danger:hover { background: #fee2e2; }

/* ===== loading & toast ===== */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.35);
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 200;
}
.spinner {
    width: 42px; height: 42px;
    border: 3px solid rgba(255,255,255,0.35); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.9s linear infinite;
}
.loading-overlay p { color: #fff; margin-top: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
    position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
    background: #1f2937; color: #fff; padding: 11px 22px; border-radius: 10px;
    z-index: 300; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* 滚动条 */
.messages::-webkit-scrollbar, .history-list::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .history-list::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.messages::-webkit-scrollbar-thumb:hover, .history-list::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* 响应式 */
@media (max-width: 640px) {
    .topbar { padding: 10px 14px; }
    .tagline { display: none; }
    .icon-btn { padding: 6px 10px; font-size: 12px; }
    .messages > * { padding: 0 4px; }
    .msg.user .bubble { max-width: 85%; }
    .history-sidebar { width: 100%; }
}
