/* 全局 */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: #f3f4f6;
  color: #1f2937;
}

.btn-primary {
  background: #4f46e5; color: #fff; border: none; border-radius: 8px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: #4338ca; }
.btn-primary:disabled { background: #a5b4fc; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent; border: 1px solid #d1d5db; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; color: #4b5563;
}
.btn-ghost:hover { background: #f9fafb; border-color: #9ca3af; }
.btn-small {
  background: #fff; border: 1px solid #d1d5db; border-radius: 6px;
  padding: 3px 9px; font-size: 12px; cursor: pointer; margin-right: 4px;
}
.btn-small:hover { background: #f3f4f6; }
.btn-small.danger { color: #dc2626; border-color: #fca5a5; }
.btn-small.danger:hover { background: #fef2f2; }
.alert-error {
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; font-size: 14px;
}

/* 登录页 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
}
.login-card {
  background: #fff; border-radius: 14px; padding: 36px 32px; width: 360px;
  box-shadow: 0 10px 30px rgba(79, 70, 229, .12);
}
.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-sub { color: #6b7280; font-size: 13px; margin: 0 0 20px; }
.login-card label { display: block; font-size: 13px; margin: 12px 0 4px; color: #374151; }
.login-card input {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: 2px solid #c7d2fe; border-color: #818cf8; }
.login-card .btn-block { margin-top: 20px; }

/* 聊天布局 */
.chat-layout { display: flex; height: 100vh; }
.sidebar {
  width: 250px; background: #111827; color: #d1d5db; display: flex;
  flex-direction: column; flex-shrink: 0;
}
.sidebar-top { padding: 12px 14px; display: flex; gap: 8px; align-items: center; }
.sidebar.collapsed { display: none; }
/* 收起/展开会话列表按钮 */
.sidebar-toggle {
  background: transparent; border: 1px solid #374151; color: #9ca3af;
  border-radius: 8px; width: 34px; height: 36px; cursor: pointer;
  font-size: 15px; flex-shrink: 0;
}
.sidebar-toggle:hover { background: #1f2937; color: #fff; }
.sidebar-expand {
  position: absolute; top: 10px; left: 10px; z-index: 10;
  background: #fff; border: 1px solid #d1d5db; color: #4b5563;
  border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.sidebar-expand:hover { background: #f9fafb; color: #111827; }
.conv-list { list-style: none; margin: 0; padding: 0 8px; flex: 1; overflow-y: auto; }
.conv-item {
  display: flex; align-items: center; border-radius: 8px; padding: 8px 10px;
  margin-bottom: 2px; cursor: pointer; font-size: 14px;
}
.conv-item:hover { background: #1f2937; }
.conv-item.active { background: #374151; color: #fff; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del {
  border: none; background: none; color: #6b7280; cursor: pointer;
  font-size: 14px; padding: 0 2px; visibility: hidden;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-del:hover { color: #f87171; }
.sidebar-bottom {
  padding: 14px; border-top: 1px solid #1f2937; display: flex;
  flex-direction: column; gap: 6px; font-size: 13px;
}
.sidebar-user { color: #e5e7eb; }
.sidebar-link { color: #9ca3af; text-decoration: none; }
.sidebar-link:hover { color: #fff; }

/* 消息区 */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 24px 32px; }
.welcome { text-align: center; color: #6b7280; margin-top: 80px; }
.msg-row { display: flex; margin-bottom: 18px; }
.msg-row.user { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 11px 15px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.65; word-break: break-word;
}
.msg-row.user .bubble {
  background: #4f46e5; color: #fff; border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg-row.assistant .bubble {
  background: #fff; border: 1px solid #e5e7eb; border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.bubble.error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

/* markdown 渲染内容 */
.bubble.md pre {
  background: #1e293b; color: #e2e8f0; padding: 12px 14px; border-radius: 8px;
  overflow-x: auto; font-size: 13px; line-height: 1.5;
}
.bubble.md code { font-family: Consolas, "Courier New", monospace; }
/* 代码块一键复制 */
.code-wrap { position: relative; }
.code-wrap .copy-btn {
  position: absolute; top: 6px; right: 6px; z-index: 1;
  border: none; border-radius: 6px; padding: 3px 10px; font-size: 12px;
  background: #475569; color: #e2e8f0; cursor: pointer; opacity: 0.85;
}
.code-wrap .copy-btn:hover { background: #6366f1; opacity: 1; }
/* AI 消息整段复制 */
.msg-col { max-width: 78%; display: flex; flex-direction: column; align-items: flex-start; }
.msg-col .bubble { max-width: 100%; }
.copy-all-btn {
  margin-top: 4px; border: none; background: transparent; color: #9ca3af;
  font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 6px;
}
.copy-all-btn:hover { background: #e5e7eb; color: #374151; }
.bubble.md :not(pre) > code {
  background: #eef2ff; color: #4338ca; padding: 1px 5px; border-radius: 4px; font-size: 13px;
}
.bubble.md p { margin: 8px 0; }
.bubble.md p:first-child { margin-top: 0; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md h1, .bubble.md h2, .bubble.md h3, .bubble.md h4 { margin: 14px 0 6px; }
.bubble.md ul, .bubble.md ol { margin: 6px 0; padding-left: 22px; }
.bubble.md table { border-collapse: collapse; }
.bubble.md th, .bubble.md td { border: 1px solid #d1d5db; padding: 4px 10px; }

/* 猜你想问 */
.suggestions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.suggestion-btn {
  background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe;
  border-radius: 999px; padding: 5px 13px; font-size: 13px; cursor: pointer;
  text-align: left; transition: background .15s;
}
.suggestion-btn:hover { background: #e0e7ff; }

/* loading 动画 */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #9ca3af;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* 输入区 */
.input-area { border-top: 1px solid #e5e7eb; background: #fff; padding: 8px 32px 10px; }
.input-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.file-hint { font-size: 12px; color: #6b7280; }
.send-hint { margin-left: auto; font-size: 12px; color: #9ca3af; }
.input-row { display: flex; gap: 10px; align-items: flex-end; }
#input {
  flex: 1; resize: vertical; min-height: 44px; max-height: 220px;
  border: 1px solid #d1d5db; border-radius: 10px; padding: 10px 12px;
  font-size: 14px; font-family: inherit; line-height: 1.5;
}
#input:focus { outline: 2px solid #c7d2fe; border-color: #818cf8; }
#btn-send { height: 44px; padding: 0 26px; }

/* 图片预览（输入区） */
.img-preview {
  display: inline-flex; align-items: flex-start; gap: 6px; margin-bottom: 8px;
  padding: 6px; border: 1px solid #e5e7eb; border-radius: 10px; background: #f9fafb;
}
.img-preview img { max-width: 120px; max-height: 90px; border-radius: 6px; display: block; }
#img-preview-remove {
  border: none; background: #e5e7eb; color: #4b5563; border-radius: 50%;
  width: 20px; height: 20px; font-size: 12px; cursor: pointer; line-height: 1;
}
#img-preview-remove:hover { background: #fca5a5; color: #7f1d1d; }

/* 消息里的图片缩略图 */
.msg-img {
  max-width: 240px; max-height: 180px; border-radius: 8px; display: block;
  margin-bottom: 8px; cursor: zoom-in; background: #fff;
}

/* 点击图片放大（简单 lightbox） */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 100;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* 管理后台 */
.admin-wrap { max-width: 1080px; margin: 0 auto; padding: 24px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; }
.admin-header h1 { font-size: 22px; }
.admin-header .sidebar-link { color: #4f46e5; margin-left: 14px; }
.admin-grid { display: flex; flex-direction: column; gap: 20px; }
.card {
  background: #fff; border-radius: 12px; padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.card h2 { font-size: 17px; margin: 0 0 16px; }
.inline-form { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form input[type=text], .inline-form input[type=password] {
  padding: 8px 11px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.checkbox-label { font-size: 14px; color: #374151; display: flex; align-items: center; gap: 4px; }
.user-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.user-table th, .user-table td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid #e5e7eb;
}
.user-table th { color: #6b7280; font-weight: 600; font-size: 13px; }
.settings-form { display: flex; flex-direction: column; gap: 6px; max-width: 480px; }
.settings-form label { font-size: 13px; color: #374151; margin-top: 8px; }
.settings-form input {
  padding: 8px 11px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.settings-actions { margin-top: 14px; display: flex; gap: 10px; }
.admin-msg { margin-top: 10px; font-size: 14px; min-height: 18px; }
.admin-msg.ok { color: #15803d; }
.admin-msg.err { color: #b91c1c; }
