/* components.css - 复用组件:消息气泡、Markdown 渲染、代码块、空状态、联网来源
 * 与原 index.html 内联样式保持完全一致
 */

/* 联网搜索开关:开启状态高亮(在顶栏的 #webSearchToggle 复用) */
#webSearchToggle.active {
  background: rgba(13, 110, 253, 0.12);
  border-color: var(--bs-primary);
  color: var(--bs-primary);
}
/* 消息中联网来源(可折叠) */
.web-sources { margin: 8px 0 2px; font-size: 12px; }
.web-sources-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--bs-border-color); background: var(--bs-tertiary-bg);
  color: var(--bs-secondary-color); border-radius: 8px;
  padding: 4px 10px; cursor: pointer; font-size: 12px; transition: all .15s ease;
}
.web-sources-toggle:hover { border-color: var(--bs-secondary-color); color: var(--bs-body-color); }
.web-sources-toggle .ws-icon { font-size: 12px; }
.web-sources-toggle .ws-caret { transition: transform .15s ease; font-size: 10px; }
.web-sources-panel {
  display: none; margin-top: 6px; padding: 8px 12px;
  border: 1px solid var(--chat-border); border-radius: 8px; background: var(--bs-tertiary-bg);
  max-height: 220px; overflow-y: auto;
}
.web-sources.open .web-sources-panel { display: block; }
.web-sources-panel .ws-link {
  display: block; color: var(--bs-primary); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 0;
}
.web-sources-panel .ws-link:hover { text-decoration: underline; }
#messages { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }

/* 消息 */
.msg { max-width: 80%; display: flex; gap: 10px; align-items: flex-start; }
.msg .avatar { width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0; display: flex;
               align-items: center; justify-content: center; font-size: 15px; user-select: none;
               overflow: hidden; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: var(--user-bg); }
.msg.user .avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.bot .avatar { background: var(--bs-secondary-bg); }
.msg .col { display: flex; flex-direction: column; min-width: 0; }
.msg .meta { font-size: 11px; color: var(--bs-secondary-color); margin-bottom: 4px; }
.msg.user .meta { text-align: right; }
.msg .bubble { padding: 12px 14px; border-radius: 12px; line-height: 1.7; font-size: 14px;
               overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bg); color: var(--user-fg, #fff); border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--bot-bg); border: 1px solid var(--chat-border); border-bottom-left-radius: 4px; overflow-x: auto; }

/* markdown 渲染 */
.msg.bot .bubble p { margin: 0 0 10px; }
.msg.bot .bubble p:last-child { margin-bottom: 0; }
.msg.bot .bubble h1, .msg.bot .bubble h2, .msg.bot .bubble h3,
.msg.bot .bubble h4, .msg.bot .bubble h5, .msg.bot .bubble h6 { margin: 16px 0 10px; line-height: 1.3; font-weight: 600; }
.msg.bot .bubble h1 { font-size: 1.4em; } .msg.bot .bubble h2 { font-size: 1.25em; }
.msg.bot .bubble h3 { font-size: 1.1em; }
.msg.bot .bubble ul, .msg.bot .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.msg.bot .bubble li { margin: 4px 0; }
.msg.bot .bubble a { color: var(--bs-primary); text-decoration: none; }
.msg.bot .bubble a:hover { text-decoration: underline; }
.msg.bot .bubble blockquote { margin: 0 0 10px; padding: 4px 12px; border-left: 3px solid var(--bs-secondary-color);
                              color: var(--bs-secondary-color); background: rgba(128,128,128,.08); border-radius: 0 6px 6px 0; }
.msg.bot .bubble hr { border: none; border-top: 1px solid var(--chat-border); margin: 12px 0; }
.msg.bot .bubble table { border-collapse: collapse; margin: 0 0 10px; width: 100%; font-size: 13px; }
.msg.bot .bubble th, .msg.bot .bubble td { border: 1px solid var(--chat-border); padding: 7px 10px; text-align: left; }
.msg.bot .bubble th { background: var(--bs-tertiary-bg); font-weight: 600; }
.msg.bot .bubble tr:nth-child(even) td { background: rgba(128,128,128,.04); }
.msg.bot .bubble :not(pre) > code { background: var(--bs-tertiary-bg); padding: 2px 6px; border-radius: 4px;
                                    font-size: 12.5px; font-family: "SFMono-Regular", Consolas, monospace; }
.msg.bot .bubble pre { background: var(--bs-tertiary-bg); border: 1px solid var(--chat-border); border-radius: 8px;
                       padding: 0; margin: 0 0 10px; overflow: hidden; position: relative; }
.msg.bot .bubble pre code { display: block; padding: 14px 14px 12px; overflow-x: auto; font-size: 13px;
                            font-family: "SFMono-Regular", Consolas, monospace; line-height: 1.6; }

/* 代码块头部 */
.code-head { display: flex; justify-content: space-between; align-items: center;
             background: var(--bs-secondary-bg); border-bottom: 1px solid var(--chat-border); padding: 6px 12px; }
.code-lang { font-size: 11px; color: var(--bs-secondary-color); letter-spacing: .3px; text-transform: uppercase; }
.copy-btn { background: transparent; border: 1px solid var(--bs-border-color); color: var(--bs-secondary-color); border-radius: 6px;
            padding: 2px 9px; font-size: 11px; cursor: pointer; transition: all .15s; }
.copy-btn:hover { color: var(--bs-body-color); border-color: var(--bs-secondary-color); }
.copy-btn.copied { color: #4ade80; border-color: #2f6b46; }

.retry-btn { margin-top: 6px; align-self: flex-start; background: var(--bs-secondary-bg); color: var(--bs-body-color);
             border: 1px solid var(--bs-border-color); border-radius: 7px; padding: 4px 12px; font-size: 12px; cursor: pointer; }

/* 空状态 */
#emptyState { margin: auto; text-align: center; color: var(--bs-secondary-color); max-width: 420px; padding: 20px; }
#emptyState .icon { font-size: 46px; margin-bottom: 14px; }
#emptyState h2 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
#emptyState p { font-size: 13px; line-height: 1.7; margin-bottom: 16px; }
#emptyState .examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#emptyState .examples button { background: var(--bs-secondary-bg); border: 1px solid var(--bs-border-color);
                               border-radius: 16px; padding: 6px 14px; font-size: 12.5px; cursor: pointer; }

.typing::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--bs-secondary-color); }
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }

.msg-stats { margin-top: 6px; font-size: 11px; color: var(--bs-secondary-color); line-height: 1.4;
             border-top: 1px dashed var(--chat-border); padding-top: 4px; }

/* ---------- 侧边栏搜索框 ---------- */
.sidebar-search-wrap { padding: 6px 8px 4px; }
.sidebar-search-wrap input { font-size: 12px; }

/* ---------- 侧边栏分组(已归档) ---------- */
.group-toggle {
  padding: 8px 12px 4px;
  font-size: 11px;
  color: var(--bs-secondary-color);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.group-toggle:hover { color: var(--bs-body-color); }
.group-toggle .caret { font-size: 10px; }

/* ---------- 侧边栏会话项新结构(主区 + badges + hover 操作)---------- */
.session-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  position: relative;
}
.session-item:hover { background: var(--bs-secondary-bg); }
.session-item.active { background: var(--active-bg); color: var(--active-fg, var(--bs-body-color)); }
.session-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}
.session-main .title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.session-badges { display: inline-flex; gap: 2px; flex-shrink: 0; }
.session-badge { font-size: 11px; opacity: 0.85; }

/* hover 操作按钮组(默认隐藏,hover 显示) */
.session-actions {
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity .12s;
  flex-shrink: 0;
}
.session-item:hover .session-actions,
.session-item:focus-within .session-actions { opacity: 1; }
.session-actions button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--bs-secondary-color);
  font-size: 12px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.session-actions button:hover {
  background: var(--bs-tertiary-bg);
  color: var(--bs-body-color);
  border-color: var(--bs-border-color);
}
.session-actions .del:hover { color: #ff6b6b; }

/* ---------- 个人中心 - 归档的会话列表 ---------- */
.archived-section {
  border-top: 1px solid var(--chat-border);
  margin-top: 12px;
  padding-top: 12px;
}
.archived-section-title {
  font-size: 12px;
  color: var(--bs-secondary-color);
  margin-bottom: 6px;
}
.archived-list { max-height: 160px; overflow-y: auto; }
.archived-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--chat-border);
}
.archived-row:last-child { border-bottom: none; }
.archived-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--bs-body-color);
}

/* ---------- 侧边栏底部(移动端操作区)----------
 * 复用 #sidebar 的 flex column 布局,margin-top: auto 把它推到最底。
 * 默认 PC 端不显示(.d-lg-none 在 HTML 上),所以只在抽屉里看得到。
 */
.sidebar-footer {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-panel);
  flex-shrink: 0;
}
.sidebar-footer .btn { font-size: 12.5px; padding: 6px 10px; }

/* ---------- 顶栏用户头像(小圆) ---------- */
.user-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--bs-secondary-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; overflow: hidden; flex-shrink: 0;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
/* 把 user-info 改成 button 后的样式修正 */
button.user-info {
  background: transparent; border: 1px solid transparent;
  padding: 2px 8px; border-radius: 8px; cursor: pointer;
  transition: background .15s;
}
button.user-info:hover { background: var(--bs-secondary-bg); }

/* ============================================================================
 * 通知(顶栏铃铛 + 下拉)
 * ========================================================================== */
.notif-wrap { position: relative; }
.notif-bell {
  position: relative;
  font-size: 16px;
  padding: 5px 10px;
}
.notif-bell-count {
  position: absolute;
  top: -2px; right: -2px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #e5484d;
  color: #fff;
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-width: calc(100vw - 24px);
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18), 0 2px 8px rgba(0, 0, 0, .10);
  z-index: 1050;
  display: none;
  flex-direction: column;
  max-height: 70vh;
  overflow: hidden;
}
.notif-dropdown.is-open { display: flex; }
.notif-dropdown-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bs-border-color);
  font-size: 13px; font-weight: 600;
}
.notif-mark-all {
  background: transparent; border: 0; padding: 4px 8px;
  color: var(--bs-primary); font-size: 12px; cursor: pointer;
  border-radius: 6px;
}
.notif-mark-all:hover { background: var(--bs-secondary-bg); }
.notif-list {
  flex: 1; overflow-y: auto;
  padding: 4px 0;
  min-height: 60px;
  max-height: 420px;
}
.notif-empty {
  text-align: center; color: var(--bs-secondary-color);
  padding: 30px 12px; font-size: 13px;
}
.notif-item {
  display: flex; gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--bs-border-color);
  transition: background .12s;
  position: relative;
}
.notif-item:hover { background: var(--bs-secondary-bg); }
.notif-item:last-child { border-bottom: 0; }
.notif-item.unread { background: color-mix(in srgb, var(--bs-primary) 5%, transparent); }
.notif-item.unread::before {
  content: "";
  position: absolute;
  left: 4px; top: 14px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--bs-primary);
}
.notif-item .ni-dot {
  width: 8px; flex-shrink: 0;
  margin-top: 6px;
}
.notif-item .ni-dot::before {
  content: ""; display: block; width: 8px; height: 8px;
  border-radius: 50%;
  background: transparent;
}
.notif-item.unread .ni-dot::before { background: var(--bs-primary); }
.notif-item .ni-main { flex: 1; min-width: 0; }
.notif-item .ni-title {
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 2px;
}
.notif-item .ni-title .ni-level {
  font-size: 10px; padding: 1px 5px; border-radius: 4px;
  font-weight: 500;
}
.notif-item .ni-title .ni-level.info    { background: rgba(13, 110, 253, .15); color: #2d5bff; }
.notif-item .ni-title .ni-level.success { background: rgba(25, 135, 84, .15);  color: #198754; }
.notif-item .ni-title .ni-level.warning { background: rgba(255, 193, 7, .18);  color: #b88500; }
.notif-item .ni-title .ni-level.error   { background: rgba(220, 53, 69, .15);  color: #dc3545; }
.notif-item .ni-body {
  font-size: 12px; color: var(--bs-secondary-color);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
  line-height: 1.5;
  white-space: pre-wrap;
}
.notif-item .ni-time {
  font-size: 11px; color: var(--bs-secondary-color);
  margin-top: 4px;
}
.notif-dropdown-foot {
  display: block; text-align: center;
  padding: 10px; font-size: 12.5px;
  color: var(--bs-primary);
  text-decoration: none;
  border-top: 1px solid var(--bs-border-color);
}
.notif-dropdown-foot:hover { background: var(--bs-secondary-bg); }

/* ---------- 个人设置大头像 ---------- */
.profile-avatar-wrap {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--bs-secondary-bg);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 38px; overflow: hidden; border: 2px solid var(--chat-border);
}
.profile-avatar-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-avatar-wrap img:not([src]),
.profile-avatar-wrap img[src=""] { display: none; }
/* 没图片时,fallback 表情占位 */
.profile-avatar-wrap #profileAvatarPlaceholder { display: block; }
.profile-avatar-wrap #profileAvatarPlaceholder:has(~ img[src]) { display: none; }
