/* ===== 基础 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f7f7f8;
  --sidebar-bg: #1e1f22;
  --sidebar-fg: #e8e8ea;
  --sidebar-muted: #9a9ba0;
  --border: #e5e5e8;
  --accent: #2f6df6;
  --accent-hover: #245ad6;
  --user-bubble: #2f6df6;
  --bot-bubble: #ffffff;
  --text: #1f2023;
  --text-muted: #6b6c70;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); overflow: hidden; }

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

/* ===== 侧栏 ===== */
.sidebar {
  width: 268px; flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-fg);
  display: flex; flex-direction: column;
  transition: margin-left .25s ease;
}
/* 桌面端收起侧栏（☰ 切换） */
.sidebar.collapsed { margin-left: -268px; }
.sidebar-head { padding: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, #4f8dff, #8b5cf6); }
.btn-new {
  width: 100%; padding: 10px 12px; border: 1px solid #3a3b40; border-radius: 10px;
  background: transparent; color: var(--sidebar-fg); font-size: 14px; cursor: pointer;
  text-align: left; transition: background .15s;
}
.btn-new:hover { background: #2b2c31; }

.doc-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; font-size: 12px; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .04em;
}
.doc-count { background: #2b2c31; border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.doc-list { list-style: none; overflow-y: auto; flex: 1; padding: 0 8px; }
.doc-list li {
  padding: 8px 10px; font-size: 13px; color: #c9cace; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: default;
}
.doc-list li:hover { background: #2b2c31; }
.doc-list li.doc-loading, .doc-list li.doc-empty { color: var(--sidebar-muted); font-style: italic; }
.doc-list li::before { content: "📄 "; }
/* 审核员的文档条目：带删除按钮（flex 布局保证长文件名省略号、按钮贴右） */
.doc-list li.has-del { display: flex; align-items: center; gap: 4px; }
.doc-list li.has-del .doc-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-del {
  flex-shrink: 0; border: none; background: transparent; cursor: pointer;
  color: var(--sidebar-muted); font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 5px;
}
.doc-del:hover { color: #f58a8f; background: #34353a; }

.sidebar-foot {
  padding: 12px 16px; font-size: 12px; color: var(--sidebar-muted);
  border-top: 1px solid #2b2c31; display: flex; align-items: center; gap: 8px;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #6b6c70; flex-shrink: 0; }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--danger); }

/* ===== 主区 ===== */
.main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  /* 夜空背景：浅色半透明蒙层压在图片上，保证深色文字可读、内容浮于其上 */
  background:
    linear-gradient(rgba(247, 247, 250, .50), rgba(247, 247, 250, .50)),
    url("/yozora.jpg") center / cover no-repeat;
}
.topbar {
  height: 56px; flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  padding: 0 20px; background: rgba(255, 255, 255, .65); border-bottom: 1px solid rgba(229, 229, 232, .6);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 16px; font-weight: 600; }
.mode-tag { margin-left: auto; font-size: 12px; color: var(--text-muted); background: #eef1f6; padding: 4px 10px; border-radius: 20px; }
.btn-menu { display: block; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); padding: 4px 8px; margin-left: -8px; border-radius: 8px; }
.btn-menu:hover { background: rgba(0, 0, 0, .06); }

/* ===== 消息区 ===== */
.messages { flex: 1; overflow-y: auto; padding: 24px 0; }
.msg-row { max-width: 820px; margin: 0 auto; padding: 6px 24px; display: flex; gap: 14px; }
.msg-row.user { flex-direction: row-reverse; }
.avatar {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.avatar.bot { background: linear-gradient(135deg, #4f8dff, #8b5cf6); color: #fff; }
.avatar.user { background: #dfe3ea; }
.bubble {
  padding: 12px 16px; border-radius: var(--radius); font-size: 15px; line-height: 1.7;
  max-width: 100%; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg-row.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.msg-row.bot .bubble {
  background: rgba(255, 255, 255, .84); border: 1px solid rgba(229, 229, 232, .7); border-top-left-radius: 4px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* markdown 内容排版 */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 8px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble code { background: #f0f1f4; padding: 1px 5px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, Consolas, monospace; }
.bubble h3 { font-size: 15px; margin: 10px 0 6px; }
.bubble strong { font-weight: 600; }

/* 来源 */
.sources { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.sources-title { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.source-item { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: #37507a;
  background: #eef2fb; border: 1px solid #dce4f5; border-radius: 8px; padding: 3px 8px; margin: 0 6px 6px 0; }

/* 打字指示 */
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #b6b8be; animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.stage-hint { font-size: 12px; color: var(--text-muted); margin-left: 8px; }

.cursor::after { content: "▋"; margin-left: 1px; animation: caret 1s step-end infinite; color: var(--accent); }
@keyframes caret { 50% { opacity: 0; } }

/* ===== 欢迎屏 ===== */
.welcome { max-width: 720px; margin: 40px auto; text-align: center; padding: 0 24px; }
.welcome h2 { font-size: 24px; margin-bottom: 10px; }
.welcome p { color: var(--text-muted); margin-bottom: 22px; }
.suggest { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: rgba(255, 255, 255, .82); border-radius: 20px; padding: 8px 14px;
  font-size: 13px; color: var(--text); cursor: pointer; transition: all .15s;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ===== 输入区 ===== */
.composer { flex-shrink: 0; padding: 12px 24px 18px; }
.composer-inner {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: rgba(255, 255, 255, .88); border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 8px 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.composer-inner:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: none; outline: none; resize: none; font-family: var(--font);
  font-size: 15px; line-height: 1.5; max-height: 160px; background: transparent; color: var(--text);
}
.btn-send {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { background: #c3cbd6; cursor: not-allowed; }
.composer-hint { max-width: 820px; margin: 8px auto 0; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===== 响应式（移动端适配） ===== */

/* 遮罩：仅移动端侧栏打开时显示 */
.backdrop {
  display: none; position: fixed; inset: 0; z-index: 15;
  background: rgba(0, 0, 0, .45); opacity: 0; transition: opacity .25s ease;
}
.backdrop.show { opacity: 1; }

@media (max-width: 760px) {
  /* 侧栏变为抽屉：占屏宽 80%（上限 300px），滑入滑出 */
  .sidebar {
    position: fixed; z-index: 20; height: 100%; height: 100dvh;
    width: 80vw; max-width: 300px; margin-left: 0;
    transform: translateX(-105%); transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, .2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open ~ .backdrop, .backdrop.show { display: block; }
  .btn-menu { display: block; padding: 8px; margin-left: -8px; }

  /* 顶栏收紧，小屏隐藏模式标签 */
  .topbar { height: 50px; padding: 0 12px; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .mode-tag { display: none; }

  /* 消息区：更窄的边距、稍小的头像和字号 */
  .messages { padding: 16px 0; }
  .msg-row { padding: 5px 12px; gap: 8px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; border-radius: 7px; }
  .bubble { padding: 10px 13px; font-size: 14.5px; }

  /* 欢迎屏 */
  .welcome { margin: 24px auto; padding: 0 16px; }
  .welcome h2 { font-size: 20px; }
  .chip { font-size: 12.5px; padding: 7px 12px; }

  /* 输入区：贴合全面屏底部安全区；字号 16px 防止 iOS 聚焦自动放大 */
  .composer { padding: 8px 10px calc(12px + env(safe-area-inset-bottom)); }
  .composer-inner { border-radius: 12px; padding: 6px 6px 6px 12px; }
  #input { font-size: 16px; }
  .btn-send { width: 40px; height: 40px; }
  .composer-hint { display: none; }
}

/* 触屏设备：去掉 hover 依赖，增大可点区域 */
@media (hover: none) {
  .doc-list li { padding: 10px 10px; }
  .btn-new { padding: 12px; }
}

/* ===== 权限分区：角色徽标 + 员工登录 ===== */
/* 顶栏角色徽标：游客灰色，员工绿色（已解锁内部文档），审核员蓝色（额外有入库审核权） */
.role-badge {
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  flex-shrink: 0; user-select: none;
}
.role-badge.guest { color: var(--text-muted); background: #eef1f6; }
.role-badge.internal { color: #fff; background: var(--ok); }
.role-badge.reviewer { color: #fff; background: var(--accent); }

.btn-login {
  flex-shrink: 0; padding: 5px 14px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--accent); border-radius: 20px;
  background: transparent; color: var(--accent); transition: background .15s;
}
.btn-login:hover { background: rgba(47, 109, 246, .08); }
.btn-login.logged { border-color: #c9cace; color: var(--text-muted); }
.btn-login.logged:hover { background: #f0f0f2; }

.welcome-tip { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* 登录弹窗：半透明遮罩 + 居中卡片 */
.login-mask {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: rgba(15, 16, 20, .45);
  align-items: center; justify-content: center;
}
.login-mask.show { display: flex; }
.login-box {
  width: 340px; max-width: calc(100vw - 40px);
  background: #fff; border-radius: var(--radius);
  padding: 24px; box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.login-box h3 { font-size: 16px; margin-bottom: 8px; }
.login-box p { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin-bottom: 14px; }
.login-box input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-err { font-size: 12.5px; color: var(--danger); min-height: 18px; margin-top: 6px; }
.login-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.login-btns button {
  padding: 8px 18px; font-size: 13.5px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.login-btns button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.login-btns button.primary:hover { background: var(--accent-hover); }

/* ===== 文档管理 / 知识入库审核 ===== */
/* hidden 属性优先：JS 切换显隐时不被下面的 display 覆盖 */
.mgr-section[hidden] { display: none; }
.mgr-section { border-top: 1px solid #2b2c31; padding-bottom: 6px; display: flex; flex-direction: column; min-height: 0; }
.mgr-body { padding: 0 16px; }
.btn-upload { text-align: center; }
.mgr-tip { font-size: 11px; color: var(--sidebar-muted); margin: 6px 2px 10px; }
.mgr-subhead { font-size: 12px; color: var(--sidebar-muted); margin: 2px 2px 4px; }
.sub-list { list-style: none; overflow-y: auto; max-height: 180px; padding: 0 8px; }
.sub-list li { padding: 7px 10px; font-size: 12.5px; color: #c9cace; border-radius: 8px; }
.sub-list li:hover { background: #2b2c31; }
.sub-list li.sub-empty { color: var(--sidebar-muted); font-style: italic; }
.sub-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--sidebar-muted); }
.sub-status { padding: 0 6px; border-radius: 8px; font-size: 11px; }
.sub-status.pending { background: #4d3f1d; color: #f5c868; }
.sub-status.approved { background: #1d3a2a; color: #5dd39e; }
.sub-status.rejected { background: #462227; color: #f58a8f; }
.sub-reason { color: #f58a8f; word-break: break-all; }
/* 待审核条目操作按钮 */
.sub-actions { display: flex; gap: 6px; margin-top: 5px; }
.sub-actions button {
  flex: 1; padding: 4px 0; font-size: 12px; cursor: pointer;
  border-radius: 6px; border: 1px solid #3a3b40; background: transparent; color: var(--sidebar-fg);
}
.sub-actions button:hover { background: #34353a; }
.sub-actions button.danger { color: #f58a8f; }

/* 审核弹窗：预览文本与表单（复用 login-mask 遮罩体系） */
.review-box { width: 560px; }
/* .login-box input 的 width:100% 是给登录口令框用的，radio 必须排除，
   否则圆圈被撑成整行宽、文字被挤到最右 */
.review-box input[type="radio"] { width: auto; margin: 0; accent-color: var(--accent); }
.review-body { font-size: 13px; margin-bottom: 10px; }
.review-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; line-height: 1.6; }
.review-preview {
  max-height: 50vh; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
  background: #f6f7f9; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-size: 12.5px; line-height: 1.6;
}
.review-radio { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.review-radio label {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
}
.review-radio label:hover { border-color: var(--accent); }
.review-body textarea {
  width: 100%; min-height: 80px; padding: 10px 12px; font-size: 13.5px; font-family: var(--font);
  border: 1px solid var(--border); border-radius: 8px; outline: none; resize: vertical;
}
.review-body textarea:focus { border-color: var(--accent); }
@media (max-width: 760px) {
  .review-box { width: calc(100vw - 32px); }
}

/* 移动端顶栏空间有限：缩小徽标与登录按钮 */
@media (max-width: 760px) {
  .role-badge { font-size: 11px; padding: 3px 8px; }
  .btn-login { font-size: 12px; padding: 4px 10px; }
  .topbar .mode-tag { display: none; }
}

