/* =============================================================
   移动端适配（企业微信内嵌 / 手机浏览器）
   - 由 server.js 注入到各页面 CSS 之后，仅在 <=768px 生效
   - 目标：真正的手机端界面，而不是把 PC 布局挤窄
   - PC 端（>768px）本文件不产生任何样式
   ============================================================= */

@media (max-width: 768px) {
  :root { --mtab-h: 56px; }

  html, body {
    width: 100%; max-width: 100%;
    /* 关键：PC 的 height:100% + overflow-x:hidden 会让 html 变成 100vh 的滚动容器，
       内容被裁剪且 window 无法滚动；手机上必须让高度随内容自适应。 */
    height: auto !important; min-height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }
  body { padding-bottom: 0; }
  body.has-mtab { padding-bottom: calc(var(--mtab-h) + env(safe-area-inset-bottom, 0px)); }

  /* ---------- 顶栏：只留一行放得下的元素 ---------- */
  .topbar, .blog-head, .post-page-head { position: sticky; }
  .topbar-inner, .post-page-head-inner, .blog-head-inner {
    height: 52px; padding: 0 12px; gap: 8px;
  }
  .brand, .post-page-brand { gap: 7px; min-width: 0; }
  .brand-logo, .post-page-brand .brand-logo {
    width: 30px; height: 30px; font-size: 15px; border-radius: 8px; flex-shrink: 0;
  }
  .brand-name, .post-page-brand-name {
    display: inline !important; font-size: 15px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
  }
  .topbar-nav, .blog-head-nav, .search-box, .blog-head-search,
  #signinBtn, .admin-area-tag { display: none !important; }
  .topbar-right, .head-actions, .blog-head-actions {
    gap: 8px; margin-left: auto; flex-shrink: 0;
  }
  .topbar-right .btn-primary, .blog-head-actions .btn-primary { display: none !important; }
  .top-icon-btn { width: 34px; height: 34px; font-size: 16px; }
  .user-name { display: none; }
  .avatar { width: 30px; height: 30px; font-size: 12px; }
  .dropdown { top: 40px; right: -6px; min-width: 180px !important; }
  .blog-brand-sep, .blog-brand-label { display: none; }

  /* ---------- 移动端工具条（搜索 + 版块横滑） ---------- */
  .mobile-toolbar { display: block; margin-bottom: 12px; }
  .mobile-toolbar.toolbar-hidden { display: none; }
  .mobile-search {
    display: flex; align-items: center; gap: 8px; height: 40px;
    padding: 0 12px; background: var(--card, #fff);
    border: 1px solid var(--border, #e5e7eb); border-radius: 10px;
  }
  .mobile-search svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--text-3, #9ca3af); fill: none; stroke: currentColor; stroke-width: 2; }
  .mobile-search input {
    flex: 1; min-width: 0; border: none; outline: none; background: transparent;
    font-size: 14px; font-family: inherit; color: var(--text, #1f2937);
  }
  .mobile-search input::placeholder { color: var(--text-3, #9ca3af); }
  .mobile-cat-bar {
    display: flex; gap: 7px; overflow-x: auto; margin-top: 10px;
    padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .mobile-cat-bar::-webkit-scrollbar { display: none; }
  .mobile-cat {
    flex-shrink: 0; border: 1px solid var(--border, #e5e7eb); background: var(--card, #fff);
    color: var(--text-2, #6b7280); border-radius: 999px; padding: 6px 13px;
    font-size: 12.5px; white-space: nowrap; cursor: pointer; font-family: inherit;
    line-height: 1.3;
  }
  .mobile-cat.active {
    background: var(--primary, #2563eb); border-color: var(--primary, #2563eb);
    color: #fff; font-weight: 500;
  }

  /* ---------- 底部 Tab ---------- */
  .mobile-tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    display: flex; height: calc(var(--mtab-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--card, #fff); border-top: 1px solid var(--border, #e5e7eb);
    box-shadow: 0 -2px 14px rgba(15, 23, 42, .06);
  }
  .mobile-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 3px; border: none; background: none;
    color: var(--text-3, #9ca3af); font-size: 10.5px; font-family: inherit;
    cursor: pointer; position: relative; padding: 4px 0;
  }
  .mobile-tab .mtab-icon { font-size: 19px; line-height: 1; }
  .mobile-tab.active { color: var(--primary, #2563eb); font-weight: 600; }
  .mobile-tab .mtab-dot {
    position: absolute; top: 5px; left: 50%; margin-left: 4px;
    min-width: 8px; height: 8px; border-radius: 4px; background: var(--danger, #ef4444);
  }

  /* ---------- 首页：侧栏彻底隐藏，内容优先 ---------- */
  /* 有 tab 的页面由 body.has-mtab 统一预留底栏高度，容器本身只留 16px 呼吸空间。
     避免早期 body 56px + 容器 86px 双重 padding 造成的大片留白。 */
  .container { padding: 10px 10px 16px; }
  .layout { display: block; }
  .sidebar { display: none !important; }
  .page-head { align-items: flex-start; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
  .page-title { font-size: 18px; }
  .page-desc { font-size: 12px; }
  .board-mods { margin-top: 6px; }
  .board-mod { padding: 2px 8px 2px 3px; }
  .board-mod span { font-size: 11px; }
  .board-locked-hint { font-size: 11px; }
  .sort-tabs { gap: 4px; margin-bottom: 10px; }
  .sort-tab { padding: 6px 14px; font-size: 12.5px; }
  .post-list { border-radius: 10px; }
  .post-item { flex-wrap: wrap; gap: 6px; padding: 13px 14px; }
  .post-main { flex: 1 1 100%; }
  .post-title-row { align-items: flex-start; flex-wrap: wrap; gap: 4px 6px; }
  .post-title {
    font-size: 14.5px; white-space: normal; line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .post-excerpt {
    font-size: 12px; white-space: normal; margin-top: 5px; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .post-meta { flex-wrap: wrap; gap: 3px 10px; margin-top: 8px; font-size: 11px; }
  /* 手机端作者名不做超链接，避免误点跳到个人主页；点击会落到帖子项本身 */
  .post-item .post-meta .author-link { pointer-events: none !important; cursor: default !important; }
  .post-item .post-meta .author-link:hover { color: var(--text-2, #6b7280) !important; text-decoration: none !important; }
  .post-stats {
    display: flex; width: 100%; gap: 16px; padding-top: 8px; margin-top: 2px;
    border-top: 1px solid var(--border-light, #f0f2f5); font-size: 11px;
  }
  .empty { padding: 44px 16px; }
  .pagination { flex-wrap: wrap; }

  /* ---------- 帖子详情（首页内渲染） ---------- */
  .detail-head { padding: 16px 16px 14px; }
  .detail-title { font-size: 19px; }
  .detail-meta { flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: 12px; }
  .detail-body { padding: 16px; font-size: 14px; line-height: 1.8; }
  .detail-actions { padding: 0 16px 16px; flex-wrap: wrap; }
  .like-btn { height: 34px; padding: 0 13px; font-size: 12px; }
  .attachments-block { margin: 0 16px 16px; padding: 12px; }
  .comments-section { margin-top: 12px; padding: 16px; border-radius: 10px; }
  .comments-title { font-size: 14px; }
  .comment-box { flex-wrap: wrap; gap: 8px; }
  .comment-box textarea { flex: 1 1 100%; min-height: 72px; font-size: 14px; }
  .comment-box .btn { margin-left: auto; }
  .comment-content, .comment-actions { margin-left: 0; }
  .comment-attachments { margin-left: 0; max-width: 100%; }
  .rich-comment .ed-area { min-height: 130px; }
  .rich-comment .rc-actions { flex-wrap: wrap; }

  /* 富文本表格不撑破屏幕 */
  .rich-content table, .detail-body table, .blog-detail-content table { display: block; overflow-x: auto; }
  .preview-doc, .preview-xlsx { padding: 16px; }

  /* ---------- 编辑页（发帖 / 写博客） ---------- */
  .post-page-main, .blog-edit-main { padding: 14px 10px 16px; }
  .post-page-title, .blog-edit-title { font-size: 18px; margin-bottom: 14px; }
  .post-card { border-radius: 10px; }
  .post-card .form-body { padding: 14px; }
  .post-card .modal-footer {
    padding: 12px 14px; flex-wrap: wrap; position: sticky; bottom: 0;
    background: var(--card, #fff); z-index: 2;
  }
  .post-card .modal-footer .btn { flex: 1; min-width: 90px; }
  .post-card .ed-area { min-height: 240px; max-height: 55vh; }
  .ed-toolbar { gap: 1px; padding: 5px; }
  .ed-btn { min-width: 28px; padding: 0 5px; font-size: 12px; }
  .tool-hint { display: none; }
  .field-label { font-size: 12.5px; }
  .field input, .field select, .field textarea { font-size: 16px; }
  .adv-row { flex-wrap: wrap; gap: 8px; }
  .adv-row input[type="text"], .adv-row input[type="password"] { flex: 1 1 100%; min-width: 0; }
  .adv-check { flex: 1 1 100%; white-space: nowrap; font-size: 13px; }
  .post-page-tip { font-size: 11px; }
  .login-gate-card { width: calc(100% - 32px); padding: 28px 20px; }

  /* ---------- 博客广场 / 我的博客 ---------- */
  .plaza-container, .blog-container { padding: 10px 10px 16px; }
  .plaza-layout, .blog-layout { display: block; }
  .blog-sidebar, .plaza-page .blog-sidebar { display: none !important; }
  .plaza-main, .blog-content { min-width: 0; }
  .plaza-header, .blog-header { align-items: flex-start; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
  .plaza-header h1, .blog-header h1 { font-size: 19px; }
  .plaza-header p, .blog-header p { font-size: 12px; }
  .plaza-toolbar { flex-wrap: wrap; }
  .plaza-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .plaza-card, .blog-card { padding: 15px 16px !important; border-radius: 10px; }
  .blog-card-title { font-size: 16px; }
  .blog-card-excerpt { font-size: 12.5px; -webkit-line-clamp: 3; }
  .blog-card-footer { flex-wrap: wrap; gap: 10px; }
  .blog-card-ops { margin-left: 0; }
  .blog-list { gap: 10px; }
  .blog-back { padding-bottom: 10px; font-size: 13px; }
  .blog-detail-card { padding: 16px; border-radius: 10px; }
  .blog-detail-author { flex-wrap: wrap; gap: 8px; }
  .blog-detail-ops { margin-left: 0; width: 100%; }
  .blog-detail-title { font-size: 21px; margin-bottom: 14px; }
  .blog-detail-content { font-size: 14px; line-height: 1.8; }
  .blog-detail-actions { flex-wrap: wrap; gap: 10px; margin-top: 20px; }
  .blog-comments { padding: 16px; margin-top: 10px; border-radius: 10px; }
  .blog-comment-box { flex-wrap: wrap; }
  .blog-comment-box textarea { flex: 1 1 100%; min-height: 72px; }
  .blog-comment-box .btn { margin-left: auto; }
  .blog-comment { gap: 8px; }
  .blog-editor-body { padding: 16px; }

  /* ---------- 登录页 ---------- */
  .login-page { min-height: 100dvh; }
  .login-top { padding: 12px 16px; }
  .login-card { width: calc(100% - 24px); padding: 26px 18px; border-radius: 14px; }
  .login-title { font-size: 20px; }
  .login-logo { width: 50px; height: 50px; font-size: 23px; }
  .login-method { height: 46px; }
  .login-copyright { padding: 12px 16px 24px; font-size: 11px; }

  /* ---------- 弹窗：底部抽屉式，避免小屏溢出 ---------- */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%; max-height: 92dvh;
    border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .modal-header { padding: 14px 18px; }
  .modal-header h3 { font-size: 16px; }
  .form-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .modal-close { top: 10px; right: 12px; }
  .profile-modal, .list-modal, .compose-modal, .blog-profile-modal, .blog-editor-modal { width: 100%; max-width: 100%; }
  .list-modal-body { max-height: 70dvh; overflow-y: auto; }

  /* 站内信：会话列表 / 聊天框二选一，由 mobile.js 切换 */
  .message-modal { height: 92dvh; max-height: 92dvh; padding: 0; overflow: hidden; }
  .msg-layout { display: block; height: 100%; }
  .msg-sidebar { height: 100%; border-right: none; }
  .msg-main { height: 100%; display: none; }
  .message-modal.mobile-chat-open .msg-sidebar { display: none; }
  .message-modal.mobile-chat-open .msg-main { display: block; }
  .mobile-msg-back {
    display: none; align-items: center; gap: 4px; border: none; background: none;
    color: var(--primary, #2563eb); font-size: 13px; padding: 4px 0; font-family: inherit;
  }
  .message-modal.mobile-chat-open .mobile-msg-back { display: inline-flex; }
  .msg-compose-bar { flex-wrap: wrap; }
  .msg-input { font-size: 16px; }

  /* 附件预览 / 图片预览全屏 */
  .preview-modal { padding: 0; }
  .preview-modal-panel { width: 100%; height: 100%; max-height: 100dvh; border-radius: 0; }
  .preview-modal-head { padding: 10px 12px; }
  .preview-modal-body { padding: 10px; }

  /* ---------- 后台管理：侧栏横滑，表格保持横向滚动 ---------- */
  .admin-shell { padding: 10px 10px 16px; gap: 10px; }
  .admin-side { padding: 5px; }
  .admin-nav-item { padding: 6px 9px; font-size: 12.5px; }
  .admin-panel { padding: 14px 12px; }
  .admin-head { flex-wrap: wrap; gap: 8px; }
  .admin-page-title { font-size: 18px; }
  .admin-toolbar { flex-wrap: wrap; }
  .admin-search { flex-basis: 100%; }
  .admin-table { min-width: 620px; }
  .admin-form-grid { grid-template-columns: 1fr; }
  .settings-form { max-width: 100%; }

  /* ---------- Toast 不遮挡底部 Tab ---------- */
  .toast { top: auto !important; bottom: calc(var(--mtab-h) + 20px) !important; max-width: calc(100vw - 28px); white-space: normal; }
  .live-banner { top: 62px; max-width: calc(100vw - 24px); font-size: 12px; padding: 7px 9px 7px 13px; gap: 8px; }
}

/* 大屏兜底：即使脚本创建过节点，PC 端也绝不显示 */
@media (min-width: 769px) {
  .mobile-toolbar, .mobile-tabbar, .mobile-msg-back { display: none !important; }
}
