/* ============ 捷途保修知识库 - DeepSeek 风格 ============ */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --sidebar-bg: #f9faff;
  --border: #e5e8ef;
  --text: #26282e;
  --text-sub: #8a8f99;
  --accent: #4d6bfe;
  --accent-soft: #eef2ff;
  --user-bubble: #eef2ff;
  --danger: #e5484d;
  --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  overflow: hidden;
}

/* 登录状态样式 */
body.logged-in .sidebar::after {
  content: '';
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  padding: 10px;
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 12px;
  color: var(--accent);
  text-align: center;
}

body.logged-in .sidebar::before {
  content: '已登录: ' attr(data-username);
  position: absolute;
  bottom: 50px;
  left: 20px;
  right: 20px;
  padding: 8px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}

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

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 17px; padding: 4px 8px 16px;
}
.logo-icon { font-size: 22px; }
.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 10px 0; border-radius: 12px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  font-size: 14px; cursor: pointer; transition: all .15s;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; margin-top: 14px; }
.side-user {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 12px; padding: 10px 12px; border-top: 1px solid var(--border);
}
.side-user-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.side-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px;
}
.side-name { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.side-admin-link { font-size: 12.5px; color: var(--accent); text-decoration: none; }
.side-admin-link:hover { text-decoration: underline; }
.side-logout {
  border: 1px solid var(--border); background: #fff; color: var(--text-sub);
  font-size: 12.5px; padding: 5px 12px; border-radius: 8px; cursor: pointer;
}
.side-logout:hover { border-color: var(--danger); color: var(--danger); }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  color: var(--text-sub); font-size: 13.5px;
  position: relative;
}
.conv-item > span {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item:hover { background: #eef1f8; color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.conv-item .del {
  flex-shrink: 0; display: none; border: none; background: none;
  color: var(--text-sub); cursor: pointer; font-size: 14px; padding: 0 4px; border-radius: 6px;
}
.conv-item:hover .del { display: block; }
.conv-item .del:hover { color: var(--danger); background: #fdeaea; }
.conv-empty { color: var(--text-sub); font-size: 12.5px; text-align: center; padding: 20px 0; }

/* ---------- 主区域 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }

/* 欢迎页 */
.welcome {
  max-width: 760px; margin: 0 auto; padding: 90px 24px 40px; text-align: center;
}
.welcome-icon { font-size: 52px; margin-bottom: 18px; }
.welcome h1 { font-size: 27px; font-weight: 700; letter-spacing: .5px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 34px; }
.chip {
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer; transition: all .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* 消息 */
.messages { max-width: 820px; margin: 0 auto; padding: 24px 24px 20px; width: 100%; }
.msg { margin-bottom: 26px; display: flex; }
.msg.user { justify-content: flex-end; flex-direction: column; align-items: flex-end; }
.msg .bubble-user {
  background: var(--user-bubble); color: var(--text);
  padding: 11px 16px; border-radius: 16px 16px 4px 16px;
  max-width: 78%; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant { flex-direction: column; }
.msg .assistant-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.msg .assistant-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.msg .assistant-name { font-weight: 600; font-size: 13.5px; }
.msg .assistant-body { line-height: 1.75; word-break: break-word; padding-left: 36px; }
.msg.refused .assistant-body { color: #9aa0ab; }

/* Markdown 简易渲染 */
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md h1,.md h2,.md h3 { margin: 14px 0 8px; font-size: 16px; }
.md ul,.md ol { margin: 4px 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md code {
  background: #f2f4f8; border: 1px solid var(--border); border-radius: 5px;
  padding: 1px 5px; font-size: 13px; font-family: Consolas, Monaco, monospace;
}
.md pre {
  background: #f7f8fa; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; margin: 8px 0;
}
.md pre code { background: none; border: none; padding: 0; }
.md blockquote {
  border-left: 3px solid var(--accent); background: #f8f9ff;
  padding: 8px 12px; margin: 8px 0; border-radius: 0 8px 8px 0; color: #55595f;
}
.md strong { font-weight: 700; }
.md table { border-collapse: collapse; margin: 8px 0; }
.md th,.md td { border: 1px solid var(--border); padding: 5px 10px; font-size: 13.5px; }

/* 处理中状态提示（识别配件 / 联网搜索） */
.status-line {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; color: var(--text-sub);
}
.status-line .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: statusBlink 1s infinite ease-in-out;
}
@keyframes statusBlink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* 打字指示 */
.typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }

/* ---------- 输入区 ---------- */
.input-wrap { padding: 0 24px 18px; }
.input-box {
  max-width: 820px; margin: 0 auto;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  background: #fff; padding: 10px 12px;
  display: flex; align-items: flex-end; gap: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77,107,254,.12); }
#input {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 15px; font-family: inherit; line-height: 1.5;
  /* 上下留白使单行时高度与发送按钮一致（36px），光标垂直居中 */
  padding: 7px 0; min-height: 36px;
  max-height: 140px; background: transparent; color: var(--text);
}
.send-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s, opacity .15s;
}
.send-btn:hover { background: #3d5bf0; }
.send-btn:disabled { background: #c6cdf9; cursor: not-allowed; }

/* ---------- 识图：图片按钮 / 预览 / 消息中的图片 ---------- */
.img-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none; flex-shrink: 0;
  background: #f1f3f8; color: var(--text-sub); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.img-btn:hover { background: #e6eaf5; color: var(--accent); }
.img-preview { max-width: 820px; margin: 0 auto 8px; gap: 10px; flex-wrap: wrap; display: none; }
.img-preview .pv { position: relative; width: 64px; height: 64px; }
.img-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; }
.img-preview .del {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; padding: 0;
  border-radius: 50%; border: none; background: #4a4f57; color: #fff; font-size: 11px;
  line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.img-preview .del:hover { background: var(--danger, #e5484d); }
.user-imgs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 8px; }
.user-imgs .thumb {
  display: block; max-width: 200px; max-height: 200px; border-radius: 12px;
  border: 1px solid var(--border); cursor: zoom-in;
}
.chat-scroll.drag-over { background: rgba(77, 107, 254, .05); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d8dce5; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #c3c9d6; }
::-webkit-scrollbar-track { background: transparent; }

/* 响应式 */
@media (max-width: 720px) {
  .sidebar { display: none; }
  .welcome { padding-top: 60px; }
  .msg .assistant-body { padding-left: 0; }
}
