/* 手机适配层：只在小视口生效，桌面端排版零改动。
   原则——真实客户端原样跑，侧栏变抽屉，内容全宽，触控放大，皮肤变量不动。 */

@media (max-width: 860px) {
  /* ---------- 布局：单栏 ---------- */
  html body .layout,
  html body .layout.sidebar-floating:not(.hidden),
  html body .layout.sidebar-collapsed {
    display: block !important;
    grid-template-columns: none !important;
    padding-left: 0 !important;
    height: 100dvh !important;
    height: 100vh;
  }

  /* ---------- 侧栏 → 抽屉 ---------- */
  html body .sidebar,
  html body .layout.sidebar-floating .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(80vw, 320px) !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 100dvh !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 10px calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    border-radius: 0 !important;
    border-left: none !important;
    transform: translateX(-106%) !important;
    transition: transform .26s ease !important;
    z-index: 210 !important;
    overflow-y: auto !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  /* 抽屉里菜单恢复"图标+文字"横排（悬浮胶囊模式只显图标，手机上要全字） */
  html body .sidebar .menu-item,
  html body .layout.sidebar-floating .menu-item {
    justify-content: flex-start !important;
    gap: 10px !important;
    padding: 10px 12px !important;
    min-height: 46px !important;
  }
  html body .sidebar .menu-item > span:not(.menu-icon),
  html body .layout.sidebar-floating .menu-item > span:not(.menu-icon) {
    display: inline !important;
  }

  html body.mobile-nav-open .sidebar,
  html body.mobile-nav-open .layout.sidebar-floating .sidebar {
    transform: none !important;
    box-shadow: 24px 0 64px rgba(0, 0, 0, .42) !important;
  }

  /* 桌面专用的折叠钮/悬浮切换钮/窗口标题栏，手机上没有意义 */
  .sidebar-collapse-btn,
  .layout-switcher-trigger,
  .app-titlebar,
  .titlebar,
  #titlebar,
  .window-titlebar {
    display: none !important;
  }

  /* ---------- 顶栏与遮罩（mobile-shim 注入） ---------- */
  .mobile-topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 14px 0 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card, rgba(16, 20, 28, .92));
    border-bottom: 1px solid var(--line, rgba(255, 255, 255, .08));
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 200;
  }
  .mobile-burger {
    width: 40px; height: 40px;
    border: 0; background: transparent;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 5px;
    cursor: pointer; flex: 0 0 auto; padding: 0;
  }
  .mobile-burger span {
    display: block; width: 20px; height: 2px; border-radius: 2px;
    background: var(--text, #e8eaf0);
  }
  .mobile-topbar-title {
    font-size: 16px; font-weight: 600;
    color: var(--text, #e8eaf0);
    letter-spacing: .02em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  .mobile-nav-mask {
    position: fixed; inset: 0; z-index: 205;
    background: rgba(6, 8, 12, .5);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  html body.mobile-nav-open .mobile-nav-mask { opacity: 1; pointer-events: auto; }

  /* ---------- 内容全宽，给顶栏让位 ---------- */
  html body .main,
  html body .layout.sidebar-floating .main {
    width: 100% !important;
    min-width: 0 !important;
    height: 100dvh !important;
    height: 100vh;
    margin: 0 !important;
    padding: calc(52px + env(safe-area-inset-top, 0px) + 12px) 14px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* ---------- 通用排版松绑（不伤皮肤） ---------- */
  .page { min-width: 0 !important; }
  img, video { max-width: 100%; height: auto; }
  table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
  input, select, textarea { font-size: 16px; } /* iOS 防聚焦放大 */
  .modal, .dialog, [role="dialog"] { max-width: 96vw !important; }
}

/* 桌面视口：适配层彻底隐身 */
@media (min-width: 861px) {
  .mobile-topbar, .mobile-nav-mask { display: none !important; }
}

/* 折叠屏展开/iPad 中间档：只收内边距，布局沿用桌面双栏 */
@media (min-width: 861px) and (max-width: 1180px) {
  html body .main { padding-left: 20px !important; padding-right: 20px !important; }
}
