/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 60, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(40, 30, 60, 0.25);
  animation: pop 0.18s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px 0;
  font-weight: 700;
  font-size: 16px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--sub);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-form { padding: 16px 20px 20px; }
.modal-mask.login-gate-mask { z-index: 400; }
.login-gate { padding: 16px 20px 22px; }
.login-gate-lead { margin: 0 0 8px; font-size: 15px; font-weight: 700; line-height: 1.6; }
.login-gate-sub { margin: 0; color: var(--sub); font-size: 13.5px; line-height: 1.7; }
.login-gate-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.login-gate-actions .btn { flex: 1 1 120px; justify-content: center; text-align: center; }
.modal:not(.modal-preview) { max-height: 90vh; display: flex; flex-direction: column; }
.modal:not(.modal-preview) #modal-body { overflow-y: auto; }
.modal:not(.modal-preview) .modal-head { flex: none; }
.modal.modal-lg { width: 96vw; max-width: min(1600px, 96vw); height: 90vh; max-height: 94vh; }
.modal.modal-lg #modal-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.comment-modal { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.comment-modal #comments-box { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }

/* ---------- 欢迎弹窗（首次进入班级空间） ---------- */
.modal-welcome { max-width: 560px; }
.modal-welcome #modal-body { padding: 16px 20px 20px; }
.modal-welcome .welcome-lead { font-size: 14.5px; line-height: 1.85; margin-bottom: 14px; }
.modal-welcome .welcome-sec { margin-bottom: 14px; }
.modal-welcome .welcome-h { font-weight: 700; font-size: 14.5px; color: var(--purple-dark); margin-bottom: 6px; }
.modal-welcome ul { margin: 0 0 0 20px; }
.modal-welcome li { font-size: 13.5px; line-height: 1.95; }
.modal-welcome .welcome-p { font-size: 13.5px; line-height: 2; }
.modal-welcome .welcome-k { display: inline-block; background: var(--purple-soft); color: var(--purple-dark); border: 1px solid var(--purple-border); border-radius: 5px; padding: 0 6px; font-size: 12.5px; font-weight: 700; }
.modal-welcome .welcome-note { font-size: 13px; color: var(--sub); line-height: 1.85; margin-bottom: 10px; }
.modal-welcome .welcome-sign { font-size: 14px; color: var(--purple-dark); font-weight: 600; margin-bottom: 12px; }
.modal-welcome .welcome-actions { position: sticky; bottom: 0; padding: 10px 0 2px; background: var(--card); border-top: 1px solid var(--border); }
html[data-theme="dark"] .modal-welcome .welcome-h,
html[data-theme="dark"] .modal-welcome .welcome-sign { color: #c9b8f5; }

/* ---------- 预览大弹窗 ---------- */
.modal-preview {
  width: 74vw;
  height: 90vh;
  max-width: 1040px;
  display: flex;
  flex-direction: column;
}
.modal-head-right { display: flex; align-items: center; gap: 10px; }
.preview-body-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.preview-body { flex: 1; min-width: 0; overflow: auto; padding: 0 20px 20px; }
.preview-tip-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  text-align: center;
  background: var(--card);
}
.preview-tip-layer .preview-loading { padding: 0; }
.preview-img-wrap { display: flex; justify-content: center; align-items: center; min-height: 300px; }
.preview-img-wrap img { max-width: 100%; max-height: calc(90vh - 130px); border-radius: 8px; }
.preview-media-wrap { display: flex; justify-content: center; }
.preview-media-wrap video { max-width: 100%; max-height: calc(90vh - 130px); border-radius: 8px; }
.preview-audio { padding: 40px 0; }
.preview-audio audio { width: 100%; max-width: 480px; }
.preview-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
  font-family: Consolas, Menlo, monospace;
  background: #f7f5fb;
  border-radius: 10px;
  padding: 16px;
  line-height: 1.6;
  margin: 0;
}
.preview-html { width: 100%; height: calc(90vh - 130px); min-height: 320px; border: none; border-radius: 8px; background: #fff; }
.preview-md { padding: 4px 6px 20px; }
.preview-loading, .preview-fallback { text-align: center; padding: 60px 20px; color: var(--sub); }
.preview-tip { display: block; margin-top: 10px; font-size: 13px; line-height: 1.7; color: var(--sub); }

/* ---------- 新消息 APP 式弹窗 ---------- */
.notify-stack {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.notify-card {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--card);
  border: 1px solid var(--purple-border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 12px 36px rgba(40, 30, 60, 0.22);
  text-decoration: none;
  color: var(--text);
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.32s;
}
.notify-card.in { transform: none; opacity: 1; }
.notify-card:hover { border-color: var(--purple); }
.notify-ico { font-size: 20px; line-height: 1.2; }
.notify-main { display: flex; flex-direction: column; min-width: 0; }
.notify-title { font-weight: 700; font-size: 13.5px; }
.notify-text {
  font-size: 13px;
  color: var(--sub);
  margin-top: 2px;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
@media (max-width: 560px) {
  .notify-stack { top: 10px; left: 10px; right: 10px; max-width: none; }
  .notify-card { transform: translateY(-140%); }
  .notify-card.in { transform: none; }
}

/* ---------- 预览缩放工具条 ---------- */
.pv-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.pv-zoom-ico { font-size: 14px; }
.pv-zoom { width: 180px; accent-color: var(--purple); cursor: pointer; }
.pv-zoom-val { font-size: 13px; color: var(--sub); min-width: 44px; text-align: center; }

/* ---------- PDF 阅读器 ---------- */
.pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.pdf-scale { font-size: 13px; color: var(--sub); min-width: 48px; text-align: center; }
.pdf-pages { font-size: 13px; color: var(--sub); margin-left: auto; }
.pdf-pages-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; padding-bottom: 10px; }
.pdf-page-box {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  line-height: 0;
}
.pdf-page { display: block; }
.docx-wrap { background: #fff; border-radius: 8px; }
.docx-wrap .docx { padding: 20px; }
.sheet-wrap { overflow: auto; background: #fff; border-radius: 8px; }
.sheet-wrap table { border-collapse: collapse; font-size: 13px; }
.sheet-wrap td, .sheet-wrap th { border: 1px solid #e3e0ea; padding: 4px 8px; }
.pptx-wrap { display: flex; justify-content: center; background: #fff; border-radius: 8px; }
.zip-list { list-style: none; margin: 0; }
.zip-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.zip-name { word-break: break-all; }
.zip-size { color: var(--sub); flex-shrink: 0; }
.zip-note { color: var(--sub); font-size: 13px; margin-bottom: 8px; }

/* ---------- 上传拖选区 ---------- */
.drop-zone {
  display: block;
  border: 2px dashed var(--purple-border);
  background: var(--purple-soft);
  border-radius: 12px;
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  margin-bottom: 14px;
  transition: all 0.15s;
}
.drop-zone:hover { border-color: var(--purple); }
.drop-zone input[type="file"] { display: none; }
.drop-text { color: var(--purple-dark); font-size: 14.5px; font-weight: 600; }

/* ---------- 响应式 ---------- */
@media (max-width: 1199px) {
  .file-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    background: var(--bg);
    padding: 8px 0 8px;
  }
  .container { padding-bottom: 64px; }

  /* 竖屏文件页：头部固定，仅卡片区滚动；评论/编辑 = 左下角浮动 */
  .page-files { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
  .page-files main.container { display: flex; flex-direction: column; overflow: hidden; min-height: 0; padding: 12px 14px 0; }
  .page-files .hero { flex-shrink: 0; }
  .files-body { flex: 1; min-height: 0; display: flex; align-items: stretch; }
  .file-side { position: fixed; left: 12px; bottom: 56px; z-index: 85; flex-direction: row; flex-wrap: wrap; width: auto; max-width: calc(100vw - 80px); align-self: auto; margin: 0; padding: 0; gap: 6px; }
  .file-side .side-btn { width: auto; padding: 8px 12px; font-size: 13px; box-shadow: var(--shadow-hover); }
  .file-side .side-div { display: none; }
  .feedback-fab { bottom: 56px; }
  .page-files .file-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: none; }
  .files-main { flex: 1; min-width: 0; overflow-y: auto; padding: 0 2px 72px; border-left: none; }

  /* 其他页正常滚动 */
  .page-board { height: auto; overflow: visible; display: block; }
  .page-board main.container { display: block; }
  .page-board .post-list { overflow: visible; }
  .page-chat { height: auto; overflow: visible; display: block; }
  .page-chat main.container { display: block; }
  .page-chat .chat-card { min-height: 60vh; }
}

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 9px 8px 9px 12px; gap: 8px; justify-content: space-between; }
  .nav-right { gap: 9px; }
  .theme-track { width: 50px; height: 27px; }
  .theme-knob { width: 21px; height: 21px; }
  html[data-theme="dark"] .theme-knob { transform: translateX(23px); }
  .nav-msg, .user-caret { width: 29px; height: 29px; }
  .user-chip { padding: 5px 11px; font-size: 13.5px; gap: 5px; }
  .scroll-toggle { padding: 3px 11px; font-size: 12.5px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -ms-overflow-style: none; }
  .nav::-webkit-scrollbar { display: none; height: 0; }
  .nav a { flex: none; white-space: nowrap; }
  .board-sections { column-gap: 6px; }
  .board-sec-div { display: none; }
  .search-row { flex-wrap: nowrap; }
  .reply-item.depth-2 { margin-left: 14px; }
  .reply-item.depth-3 { margin-left: 28px; }
  html:not(.landing) .hero-title { font-size: 32px; }
  .container { padding: 20px 14px 50px; }
  .modal-preview { width: 96vw; height: 92vh; }
  .page-files .file-grid { grid-template-columns: 1fr; }
  .tag-edit-btn { position: static; transform: none; }
}

/* ---------- 平板竖屏：站内顶栏分两排，四个导航下移一行（避免文字竖排） ---------- */
@media (min-width: 721px) and (max-width: 1024px) and (orientation: portrait) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; row-gap: 8px; }
  .nav { order: 3; flex: 1 1 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; -ms-overflow-style: none; }
  .nav::-webkit-scrollbar { display: none; height: 0; }
  .nav a { flex: none; white-space: nowrap; }
}

/* ---------- 移动端兜底：文字宁可省略/横向滚动，也绝不挤成竖排 ---------- */
@media (max-width: 900px) {
  /* 顶栏账号区不参与压缩 */
  .nav-right { flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; }
  .user-menu { flex: none; }
  .user-chip { white-space: nowrap; }

  /* 表格：保留表格结构，超出屏幕时整表横向滚动；单元格文字不换行 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-table { width: 100%; min-width: 760px; }
  .admin-table th,
  .admin-table td { white-space: nowrap; }
  .admin-table .admin-actions { white-space: nowrap; }
  .admin-table .login-ua { max-width: 260px; }

  /* 横向 flex 里的短文本：超长就省略，不再逐字换行 */
  .msg-from,
  .chat-head-title,
  .fc-author,
  .user-row-name,
  .msg-conv-name,
  .conv-name,
  .post-author { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-head-title { flex: 1 1 auto; }
  .msg-time,
  .fc-time,
  .reply-time,
  .conv-time,
  .user-row-meta,
  .profile-item-meta { flex: none; white-space: nowrap; }
  .chat-head .btn,
  .msg-head .btn,
  .file-comment-head .comment-like { flex: none; }
}

@media (max-width: 720px) {
  /* 消息页：会话列表独占一整行，不再被标签栏挤扁 */
  .msg-conv-list { flex: 1 1 100%; width: 100%; }
  .msg-conv { width: 100%; }
  .msg-readall { flex: 1 1 100%; width: 100%; margin: 8px 0 0; }

  /* Markdown 表格：小屏横向滚动，避免列被压成一字一行 */
  .markdown-body table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .markdown-body th,
  .markdown-body td { white-space: nowrap; }
}

@media (max-width: 560px) {
  /* 统计卡片排成 3 列，减少纵向拉长 */
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
  .stat-box { padding: 12px 6px; }
  .stat-num { font-size: 20px; }

  /* 个人主页列表：标题与时间上下排，避免互相挤压 */
  .profile-item { flex-direction: column; align-items: flex-start; gap: 2px; }
  .profile-item-meta { margin-left: 0; white-space: normal; }

  /* 卡片详情弹窗留出更多正文宽度 */
  .card-view { padding: 26px 18px; border-radius: 16px; }
  .card-view .file-title { font-size: 19px; }
}

/* ---------- 深色模式开关 ---------- */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
}
.theme-track {
  position: relative;
  width: 56px;
  height: 29px;
  border-radius: 999px;
  background: transparent;
  border: 1.5px solid var(--border);
  display: inline-block;
  transition: background 0.25s, border-color 0.25s;
}
.theme-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s;
}
.theme-knob::before { content: '☀️'; }
html[data-theme="dark"] .theme-knob { transform: translateX(27px); }
html[data-theme="dark"] .theme-knob::before { content: '🌙'; }
html[data-theme="dark"] .theme-track { background: transparent; }
html[data-theme="dark"] .nav-msg,
html[data-theme="dark"] .user-caret { background: #2a2438; border-color: var(--purple-border); }

/* ---------- 深色模式配色 ---------- */
html[data-theme="dark"] {
  --bg: #16121f;
  --card: #201a2e;
  --border: #3f3457;
  --text: #eae4f5;
  --sub: #a296b8;
  --purple-soft: #2b2342;
  --purple-border: #4a3b6b;
  --gold-soft: #2f2815;
  --danger-soft: #402328;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.4), 0 10px 26px rgba(0, 0, 0, 0.45);
}
body { transition: background 0.25s, color 0.25s; }
.card, .topbar, .modal, .reply-main, .msg-item, .search-input { transition: background 0.25s, border-color 0.25s; }
html[data-theme="dark"] .topbar { background: rgba(22, 18, 31, 0.6); }
html[data-theme="dark"] .search-input,
html[data-theme="dark"] .field input[type="text"],
html[data-theme="dark"] .field input[type="password"],
html[data-theme="dark"] .field select,
html[data-theme="dark"] .field textarea {
  background: #221c33;
  color: var(--text);
}
html[data-theme="dark"] .search-input:focus,
html[data-theme="dark"] .field input:focus,
html[data-theme="dark"] .field select:focus,
html[data-theme="dark"] .field textarea:focus {
  background: #221c33;
}
html[data-theme="dark"] .user-menu-pop,
html[data-theme="dark"] .tag-chip,
html[data-theme="dark"] .reply-main,
html[data-theme="dark"] .msg-item,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .btn-outline { background: var(--card); }
html[data-theme="dark"] .flash-error { background: #3a2126; color: #e89393; border-color: #57303a; }
html[data-theme="dark"] .flash-success { background: #1d3a2a; color: #8fd8ad; border-color: #2c4f3c; }
html[data-theme="dark"] .flash-deleted { background: #3a2126; color: #f0a6a6; border-color: #57303a; }
html[data-theme="dark"] .del-remove button { background: #3a2126; color: #f0a6a6; border-color: #57303a; }
html[data-theme="dark"] .del-remove button:hover { background: #4a2a30; }
html[data-theme="dark"] .markdown-body blockquote { color: #cbb25a; }
html[data-theme="dark"] .preview-text { background: #221c33; color: var(--text); }
html[data-theme="dark"] .docx-wrap,
html[data-theme="dark"] .sheet-wrap,
html[data-theme="dark"] .pptx-wrap { background: var(--card); }
html[data-theme="dark"] .sheet-wrap td,
html[data-theme="dark"] .sheet-wrap th { border-color: #453a5e; }
html[data-theme="dark"] .role-badge { background: #342a48; color: var(--sub); }
html[data-theme="dark"] .role-badge.role-mentor { background: #3c2132; color: #e293bd; }
html[data-theme="dark"] .role-admin { background: var(--purple-soft); color: #c9b8f5; }
html[data-theme="dark"] .role-mentor { background: #3c2132; color: #e293bd; }
html[data-theme="dark"] .role-owner { background: var(--gold-soft); color: #d9bc5e; }
html[data-theme="dark"] .board-hero { background: linear-gradient(120deg, #241d3a, #1b1528); border-color: #3a2f55; }
html[data-theme="dark"] .board-hero.accent-fun { background: linear-gradient(120deg, #2c2512, #1b1528); border-color: #4a3f1e; }
html[data-theme="dark"] .ft-red { background: #3d2226; color: #e39393; }
html[data-theme="dark"] .ft-blue { background: #1e2b44; color: #8db6e8; }
html[data-theme="dark"] .ft-green { background: #1d3427; color: #8ccfab; }
html[data-theme="dark"] .ft-orange { background: #3a2a18; color: #e0ab6d; }
html[data-theme="dark"] .ft-yellow { background: var(--gold-soft); color: #d9bc5e; }
html[data-theme="dark"] .ft-pink { background: #3c2132; color: #e293bd; }
html[data-theme="dark"] .ft-purple { background: var(--purple-soft); color: #c9b8f5; }
html[data-theme="dark"] .ft-cyan { background: #1c3238; color: #8ccdd6; }
html[data-theme="dark"] .ft-gray { background: #2d2737; color: #b3a9c4; }
html[data-theme="dark"] .msg-unread { background: var(--purple-soft); }
html[data-theme="dark"] .fc-author { color: #c9b8f5; }
html[data-theme="dark"] .comment-form textarea { background: #221c33; color: var(--text); }
html[data-theme="dark"] .tag-chip:hover { border-color: var(--purple); color: #c9b8f5; }
html[data-theme="dark"] .tag-clear { border-color: #57303a; }
html[data-theme="dark"] .mode-hint { background: var(--gold-soft); color: #d9bc5e; border-color: #4a3f1e; }
html[data-theme="dark"] .side-btn.side-white { background: #2a2438; color: var(--text); border-color: var(--purple-border); }
html[data-theme="dark"] .side-btn.side-yellow { background: #4a3f1e; border-color: var(--gold); color: #d9bc5e; }
html[data-theme="dark"] .side-btn.side-purple { background: #2f2745; border-color: var(--purple); color: #c9b8f5; }
html[data-theme="dark"] .side-btn.side-red { background: #3a2323; border-color: var(--danger); color: #f0a0a0; }
html[data-theme="dark"] .side-btn.on { background: #3d3060; border-color: var(--purple); color: #c9b8f5; }
html[data-theme="dark"] .side-btn.side-white.on { background: #1f1a2e; color: #d8cdf0; border-color: var(--purple); }
html[data-theme="dark"] .side-btn.side-yellow.on { background: #5c4d1f; color: #f0d98a; border-color: var(--gold); }
html[data-theme="dark"] .side-btn.side-purple.on { background: #3d3060; color: #c9b8f5; border-color: var(--purple); }
html[data-theme="dark"] .side-btn.side-red.on { background: #4a2a2a; color: #f0a0a0; border-color: var(--danger); }
html[data-theme="dark"] .tag-edit-btn { color: #c9b8f5; }
html[data-theme="dark"] .user-menu-pop a:hover,
html[data-theme="dark"] .user-menu-pop .link-btn:hover { background: var(--purple-soft); color: #c9b8f5; }

