* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f4f6f8;
  color: #1f2933;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1e3a5f 0%, #2d6a9f 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: min(360px, 90vw);
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
  text-align: center;
}
.logo { font-size: 28px; font-weight: 700; color: #1e3a5f; letter-spacing: 1px; }
.subtitle { color: #7b8794; font-size: 13px; margin: 8px 0 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  padding: 12px 14px;
  border: 1px solid #d9e2ec;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
}
#login-form input:focus { border-color: #2d6a9f; }
#login-form button {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #2d6a9f;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:hover { background: #1e5a8a; }
.login-error { color: #d64545; font-size: 13px; min-height: 18px; }

/* ---------- 聊天页 ---------- */
.chat-view {
  flex: 1;
  display: flex;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
/* 侧边栏 */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #16283b;
  color: #dbe4ee;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-title { font-size: 14px; font-weight: 700; color: #fff; letter-spacing: 1px; }
.new-chat-btn {
  border: 1px solid rgba(255,255,255,.25);
  background: transparent;
  color: #cfe0f0;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.new-chat-btn:hover { background: rgba(255,255,255,.12); }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 13px;
}
.conv-item:hover { background: rgba(255,255,255,.08); }
.conv-item.active { background: #2d6a9f; color: #fff; }
.conv-item .conv-title {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.conv-item .conv-time { font-size: 11px; opacity: .6; flex-shrink: 0; }
.conv-del {
  border: none;
  background: transparent;
  color: inherit;
  opacity: .4;
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  flex-shrink: 0;
}
.conv-item:hover .conv-del { opacity: .9; }
.conv-del:hover { color: #ff8a8a !important; opacity: 1; }
.conv-empty { color: #7b8794; font-size: 13px; text-align: center; padding: 24px 10px; }
.sidebar-footer {
  padding: 10px 14px;
  font-size: 11px;
  color: rgba(255,255,255,.35);
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 40;
}
/* 右侧主区 */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #fff;
  border-bottom: 1px solid #e4e7eb;
  position: sticky; top: 0;
  gap: 10px;
}
.menu-btn {
  border: 1px solid #d9e2ec;
  background: #fff;
  color: #52606d;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}
.chat-title { font-weight: 700; color: #1e3a5f; font-size: 17px; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.logout-btn {
  border: 1px solid #d9e2ec;
  background: #fff;
  color: #52606d;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.logout-btn:hover { background: #f5f7fa; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }
.bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.65;
  font-size: 15px;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .bubble { background: #2d6a9f; color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble {
  background: #fff;
  border: 1px solid #e4e7eb;
  border-bottom-left-radius: 4px;
  white-space: normal;
}
/* Markdown 内部样式 */
.bubble h1, .bubble h2, .bubble h3 { margin: 10px 0 6px; line-height: 1.4; }
.bubble h1 { font-size: 1.35em; } .bubble h2 { font-size: 1.2em; } .bubble h3 { font-size: 1.05em; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble code { background: #f0f3f7; padding: 2px 5px; border-radius: 4px; font-size: 13px; font-family: Consolas, Monaco, monospace; }
.bubble pre {
  background: #f6f8fa;
  border: 1px solid #e4e7eb;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: transparent; padding: 0; font-size: 13px; }
.bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.bubble th, .bubble td { border: 1px solid #d9e2ec; padding: 6px 10px; text-align: left; }
.bubble th { background: #f0f3f7; }
.bubble blockquote { border-left: 3px solid #2d6a9f; padding-left: 12px; color: #52606d; margin: 8px 0; }
.bubble a { color: #2d6a9f; }
.bubble img { max-width: 100%; border-radius: 6px; }

/* ---------- 输入栏 ---------- */
.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid #e4e7eb;
  align-items: flex-end;
}
#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid #d9e2ec;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  max-height: 200px;
  line-height: 1.5;
}
#chat-input:focus { border-color: #2d6a9f; }
#send-btn {
  padding: 12px 22px;
  border: none;
  border-radius: 12px;
  background: #2d6a9f;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#send-btn:disabled { opacity: .55; cursor: not-allowed; }

/* 移动端适配 */
@media (max-width: 700px) {
  .bubble { max-width: 92%; }
  .messages { padding: 14px 10px; }
  .menu-btn { display: block; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.35); }
}
