/* ---------- 基础变量 ---------- */
:root {
  --bg: #F4FAF7;           /* 浅绿色背景 */
  --card: #FFFFFF;
  --line: #CCE0D6;         /* 浅绿线条 */
  --muted: #4B6B57;        /* 辅助绿 */
  --primary: #2E7D5E;      /* 主绿色 */
  --primary-weak: #D0E8DC; /* 浅绿底 */
  --radius: 14px;
  --radius-lg: 20px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(0,0,0,.06);
  --sidebar-w: 5vw;
  --det-juzi: #ff4d4f;     /* 句子框红 */
  --det-char: #1677ff;     /* 字符框蓝 */
  --det-label-bg: rgba(0,0,0,.35); /* 标签底色 */
}

/* ---------- 全局 ---------- */
* {
  box-sizing: border-box;
}

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, Arial, sans-serif;
  height: 100%;
  margin: 0;
  overflow-y: hidden;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  background: #2E7D5E;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 20px;
  left: 0;
  padding: 1vw;
  position: fixed;
  top: 0;
  bottom: 0;
  width: var(--sidebar-w);
}

/* 新增：返回按钮样式 */
.btn {
  margin-top: auto; /* 将按钮推到底部 */
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
}

.btn .chip {
  background: rgba(255, 255, 255, 0.15);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: white; /* 设置图标颜色为白色 */
}

.btn .chip i {
  color: white; /* 确保图标颜色为白色 */
}

.btn span {
  color: white;
  font-size: 12px;
  text-align: center;
}

.menu-btn {
  background: var(--bg);
  border: none;
  border-radius: 20%;
  box-shadow: var(--shadow);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  aspect-ratio: 1;
  justify-content: center;
  width: 100%;
  align-self: center;
  align-items: center;
}

.menu-lines,
.menu-lines::before,
.menu-lines::after {
  background: var(--primary);
  content: "";
  display: block;
  height: 2px;
  width: 18px;
}

.menu-lines::before {
  position: relative;
  top: -6px;
}

.menu-lines::after {
  position: relative;
  top: 6px;
}


.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: center;
  width: 100%;
  aspect-ratio: 1;
}

/* ---------- 顶栏 ---------- */
.topbar {
  align-items: center;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 8vh;
  justify-content: space-between;
  padding: 0 3vh;
  position: sticky; /* 跟随内容区滚动 */
  top: 0;
  z-index: 10;
}

.topbar-left {
  color: var(--primary);
  font-size: 3vh;
  font-weight: 700;
}

.topbar-right .topbar-logo {
  height: 80%;
  width: auto;
}

/* ---------- 主体 ---------- */
.hero {
  height: 92vh;
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  padding: 10px 20px;
}

.headline {
  color: #3b2618;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 1.25;
  margin: 20px 0 28px;
}

/* ---------- 提问卡片 ---------- */
.ask-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 750px;
  padding: 20px;
  text-align: left;
  margin-top: 12px;
  margin-bottom: 16px;
}

.input-wrap {
  background: #FFFEFC;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  padding: 14px 16px 12px 16px;
  position: relative;
}

textarea {
  border: none;
  border-radius: 16px;
  font-size: 18px;
  height: 50px;
  line-height: 1.6;
  margin-bottom: 12px;
  min-height: 50px;
  outline: none;
  padding: 0 6px;
  resize: vertical;
  width: 100%;
}

textarea::placeholder {
  color: #9e8778;
}

/* ---------- 标签/按钮 ---------- */
.inline-actions{
  display:flex;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
}

.chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 18px;
  gap: 4px;
  padding: 8px 14px 8px 8px;
  text-decoration: none;
  transition: 0.2s ease;
  align-items: center;
}

.chip-primary {
  background: var(--bg);
  border-color: #A8D5C0;
  color: var(--primary);
}

.chip span {
    transition: all 0.3s ease;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(46, 125, 94, 0.2); /* 内外发光效果 */
  color: #fff;
}

.chip.active .chip-svg {
  fill: #fff;
}

.chip-icon {
  font-size: 20px;
  font-weight: 700;
  margin-right: 4px;
}

.small-chip {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  gap: 8px;
  padding: 8px 12px;
  transition: 0.2s;
}

.small-chip:hover {
  background: #FFFBF8;
}

.small-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.small-chip .dot {
  background: var(--primary-weak);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--primary);
  display: inline-block;
  height: 10px;
  width: 10px;
}

.square-icon {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-grid;
  height: 40px;
  margin-left: auto;
  place-items: center;
  transition: 0.2s;
  width: 40px;
}

.square-icon:hover {
  transform: translateY(-1px);
}

.square-icon.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  margin-left: -2px;
}

/* 24px 图标统一 */
.icon-24 {
  fill: currentColor;
  height: 24px;
  width: 24px;
}

/* 功能按钮行 */
.feature-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-start;
  margin-top: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

/* 侧栏“新对话”按钮圆形化（仅在侧栏内生效） */
.sidebar .chip-primary {
  display: grid;
  font-size: 1vw; /* “＋”更大 */
  padding: 0;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
}

.sidebar .chip-primary .chip-icon {
  font-size: 18px;
  margin: 0;
}

/* ---------- 工作区与右侧预览面板 ---------- */
.workspace {
  display: grid;
  grid-template-columns: 1fr;
  height: 92vh;
}

.media-panel {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 92vh;
  margin-right: 20px;
  margin-top: 20px;
  overflow: hidden; /* 面板自身不滚动，内部 grid 滚动 */
  padding-bottom: 16px;
  padding-top: 12px;
  position: relative;
  width: auto;
}

.media-panel.hidden {
  display: none;
  width: 0px;
}

.media-header-wrap {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: flex-start; /* 头部标题靠左排成一行 */
  gap: 12px;                   /* 标题之间的间距 */
  margin-bottom: 10px;
  padding: 3px 16px 0px 16px;
  flex-wrap: nowrap;           /* 不换行 */
}

.media-header {
  color: var(--muted);
  font-size: 16px;
  font-weight: 700;
  margin-left: 5px;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-top-left-radius: 10px;   /* 仅上方圆角 */
  border-top-right-radius: 10px;
  border-bottom-left-radius: 0;   /* 下方直角 */
  border-bottom-right-radius: 0;
  padding: 10px;
}

.media-header.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(46, 125, 94, 0.2); /* 内外发光效果 */
  color: #fff;
}


/* 让多个 media-header 同排且不换行 */
.media-header {
  white-space: nowrap;
}

/* 关闭按钮在最右侧 */
#closePanel {
  margin-left: auto;
}

.media-grid {
  align-content: start;
  align-items: start;
  display: grid;
  flex: 1; /* 占满剩余高度 */
  gap: 14px;
  min-height: 0; /* 允许子元素在 flex 容器中正确滚动 */
  overflow-y: auto; /* 只让下方网格区域滚动 */
}

.media-grid.hidden {
  display: none;
}

.show-tapian {
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 16px 18px 20px;
}

.show-det {
  padding: 10px 24px
}

.media-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  position: relative; /* 为 ::before 和绝对定位图片做容器 */
}

/* 兼容性：用内边距方案确保高度，避免旧浏览器不识别 aspect-ratio 导致重叠 */
.media-item::before {
  content: "";
  display: block;
  padding-top: 100%;
}

.media-item img {
  display: block;
  left: 50%;
  max-height: 95%;
  max-width: 95%;
  object-fit: contain; /* 保持比例 */
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
}

/* 面板打开时，主区域 + 右侧面板并排 */
.content.panel-open .workspace {
  align-items: center;
  grid-template-columns: 55% 45%;
}

.content {
  margin-left: var(--sidebar-w); /* 与侧栏同宽 */
  min-height: 100vh;
  padding: 0 0;
}

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  :root {
    --sidebar-w: 220px;
  }

  .content.panel-open .workspace {
    grid-template-columns: 55% 45%;
  }

  .media-panel {
    width: 300px;
  }
}

@media (max-width: 640px) {
  :root {
    --sidebar-w: 100%;
  }

  .ask-card {
    padding: 18px;
  }

  .content {
    margin-left: 0;
    margin-top: 88px;
  }

  .content.panel-open .workspace {
    grid-template-columns: 1fr;
  }

  .headline {
    font-size: 28px;
  }

  .media-panel {
    border-left: none;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 12px;
    width: auto;
  }

  .sidebar {
    align-items: center;
    border-bottom: 1px solid var(--line);
    border-right: none;
    bottom: auto;
    flex-direction: row;
    height: auto;
    position: fixed;
    width: 100%;
  }

  .square-icon {
    height: 40px;
    width: 40px;
  }
}

/* ---------- 功能层 ---------- */
/* ---- 图片放大预览 ---- */
.lightbox {
  align-items: center;
  background: rgba(0,0,0,0.8);
  display: flex;
  height: 100%;
  justify-content: center;
  left: 0;
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 9999;
}

.lightbox img {
  border-radius: 8px;
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
  max-height: 90%;
  max-width: 90%;
  object-fit: contain;
}

.lightbox.hidden {
  display: none;
}

/* 右上角关闭按钮 */
.media-panel .close-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 24px;
  position: absolute;
  right: 20px;
  transition: color 0.2s;
}

.media-panel .close-btn:hover {
  color: var(--primary);
}

/* 右下角“＋”按钮 */
.media-item .add-btn {
  background: var(--primary);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow);
  color: #fff;
  cursor: pointer;
  display: grid;
  font-size: 20px;
  height: 34px;
  line-height: 1;
  place-items: center;
  position: absolute;
  right: 8px;
  bottom: 8px;
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.15s ease;
  width: 34px;
  z-index: 1; /* 确保盖在图片上 */
  opacity: 0.95;
}

.media-item .add-btn:hover {
  box-shadow: 0 6px 16px rgba(0,0,0,.12);
  opacity: 1;
  transform: translateY(-1px);
}

/* 选中预览条（位于 input-wrap 内部） */
.chosen-bar {
  margin-bottom: 8px; /* 与 textarea 保持间距 */
}

.chosen-bar.hidden {
  display: none;
}

/* 右侧面板中被选择的卡片高亮（单选反馈） */
.media-item.selected {
  box-shadow: 0 0 0 3px var(--primary) inset;
}

/* 单选模式：预览网格改为单列 1:1 缩略图 */
.chosen-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 80px; /* 只显示一张 */
  margin-left: 4px;
}

/* 直接追加的预览图片样式（单选逻辑下使用 .chosen-image） */
.chosen-image {
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: block;
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.thumb-item {
  align-items: center;
  aspect-ratio: 1 / 1; /* 保持方形 */
  display: flex;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.thumb-item img {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

/* 缩略图删除按钮（×） */
.remove-thumb {
  align-items: center;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow);
  color: #fff;
  cursor: pointer;
  display: flex;
  font-size: 14px;
  height: 18px;
  justify-content: center;
  line-height: 1;
  position: absolute;
  right: 6px;
  top: 6px;
  width: 18px;
}

.remove-thumb:hover {
  filter: brightness(1.05);
}

/* ---- 检测框覆盖层（HTML 元素版） ----
   说明：覆盖层尺寸与图片保持一致（图片最大占容器 95% 且居中），
        坐标使用百分比定位，缩放自适应。 */
.det-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  /* 与 .media-item img 的 max-width/height 对齐，并居中 */
  max-width: 95%;
  max-height: 95%;
  left: 2.5%;
  top: 2.5%;
}

/* 公共样式 */
.det-label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(0, -100%);
  font: 12px/1 sans-serif;
  color: #fff;
  background: var(--det-label-bg);
  padding: 2px 4px;
}

.juzi-box,
.char-box {
  position: absolute;
  box-sizing: border-box;
}

/* 句子框（红） */
.juzi-box {
  border: 2px solid var(--det-juzi);
  z-index: 1;
}
.juzi-box > .det-label {
  background: rgba(255, 77, 79, .85);
}

/* 字符框（蓝） */
.char-box {
  border: 2px solid var(--det-char);
  z-index: 2;
  transition: box-shadow .18s ease;
}
.char-box > .det-label {
  background: rgba(22, 119, 255, .85);
}
.char-box:hover {
  box-shadow: 0 0 12px rgba(22, 119, 255, .9);
}

/* 悬停脉动动画（可由 JS 添加 .hover 切换） */
@keyframes det-pulse {
  0% { box-shadow: 0 0 8px rgba(22, 119, 255, .4); }
  50% { box-shadow: 0 0 20px rgba(22, 119, 255, 1); }
  100% { box-shadow: 0 0 8px rgba(22, 119, 255, .4); }
}
.char-box.hover {
  animation: det-pulse .8s ease-in-out infinite;
}

.is-hidden { display: none !important; }

/* 对话框外层容器 */
.message_body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 1000px;
  height: auto;
  overflow: auto;          /* 内容溢出时滚动 */
  scrollbar-width: none;     /* Firefox 隐藏滚动条 */
  -ms-overflow-style: none;  /* 旧版 Edge/IE 隐藏滚动条 */
  padding: 1px;
}

/* 隐藏 .message_body 的滚动条（仍可滚动） */
.message_body::-webkit-scrollbar { width: 0; height: 0; }
.message_body::-webkit-scrollbar-track { background: transparent; }
.message_body::-webkit-scrollbar-thumb { background: transparent; }

/* 单条消息容器：默认靠左 */
.message_item {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

/* 右侧消息：行内元素右对齐 */
.message_item.right {
  justify-content: flex-end;
  flex-wrap: wrap; /* 多图时自动换行 */
  gap: 8px;
}

/* 气泡本体（用于文字消息） */
.message_item .bubble {
  max-width: 90%;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  color: #111;
  font-size: 16px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  text-align: justify;              /* 气泡内文字两端对齐 */
}

/* 右侧气泡样式 */
.message_item.right .bubble {
  background: #e6f2ff;
  border: 1px solid #BCD8FF; /* 淡蓝色边框，增强层次 */
}

/* 在 message_item 中直接放入 img 时，视为图片气泡 */
.message_item img {
  display: block;
  max-height: 200px;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

/* 给左/右两种方向预留不同圆角（针对文字气泡） */
.message_item .bubble {
  border-top-left-radius: 6px;
}
.message_item.right .bubble {
  border-top-right-radius: 6px;
  border-top-left-radius: 14px;
}

.bubble span {
  white-space: pre-wrap; /* 让 \n 变成可见换行，同时保留多空格/制表 */
  tab-size: 4;           /* 可选：控制 \\t 的显示宽度 */
}

.bubble.char img {
  border-radius: none;
  box-shadow: none;
}

#mediaGrid-char {
  padding: 10px 24px;
}


.literature-container {
  padding: 5px 10px;
  max-width: 1200px;
  margin: 5px auto;
  height: calc(100vh - 130px);
  overflow-y: auto;
}

.literature-container2 {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  height: calc(100vh);
  overflow-y: auto;
}

.literature-header {
  text-align: center;
  margin-bottom: 1px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  padding: 1px 0; /* 修改：水平方向0，垂直方向1px */
  border-radius: var(--radius);
  font-size: 11px;
}

.literature-category {
  margin-bottom: 30px;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.literature-category2 {
  margin-bottom: 50px;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.category-title {
  color: var(--primary);
  font-size: 22px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.subcategory {
  margin-bottom: 20px;
}

.subcategory2 {
  height: 380px;
  margin-bottom: 5px;
}

.subcategory-title {
  color: var(--muted);
  font-size: 18px;
  margin-bottom: 12px;
}

.literature-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
  max-height: 430px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.literature-item {
  padding: 10px 15px;
  margin-bottom: 8px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--primary);
  transition: all 0.2s ease;
}

.literature-item:hover {
  background: var(--primary-weak);
  transform: translateX(5px);
}

.item-content {
  font-size: 16px;
  color: #333;
}

.author {
  color: var(--primary);
  font-weight: 500;
  margin-left: 5px;
}

.stats-box {
  background: var(--primary-weak);
  padding: 15px;
  border-radius: var(--radius);
  text-align: center;
  margin-top: 30px;
  position: sticky;
  bottom: 0;
}

/* 滚动条样式 */
.literature-container::-webkit-scrollbar {
  width: 8px;
}

.literature-container::-webkit-scrollbar-track {
  background: var(--bg);
  border-radius: 4px;
}

.literature-container::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

.literature-container::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.literature-list::-webkit-scrollbar {
  width: 6px;
}

.literature-list::-webkit-scrollbar-track {
  background: var(--card);
  border-radius: 3px;
}

.literature-list::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 3px;
}

/* 返回顶部按钮 */
.back-to-top {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--primary);
  color: white;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  z-index: 100;
  opacity: 0.8;
}

.back-to-top:hover {
  opacity: 1;
  transform: translateY(-5px);
}

/* 响应式调整 */
@media (max-width: 640px) {
  .literature-container {
    padding: 15px;
    height: calc(100vh - 80px);
  }
  
  .literature-category {
    padding: 10px;
  }
  
  .category-title {
    font-size: 20px;
  }
  
  .literature-list {
    max-height: 200px;
  }
  
  .back-to-top {
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
  }
}

.not-collected {
  color: rgb(121, 50, 50);
  margin-left: 4px; /* 可选：添加一点间距 */
}

.item-content2 {
      font-size: 16px;
      color: #a5a2a2;
}

