/* ============================================================
   Darra GitLab 窄屏适配 + 嵌入 UX (darra-ux-narrow.css)
   2026-08-05 · git.darra.xyz 工业 SCL 代码仓储
   场景: 嵌入 PLC IDE / AI Studio 侧边栏面板的桌面 WebView
   (窄屏 ≈ 320-800px, 鼠标操作, 非手机触屏)
   只作用于窄屏 (media query), 桌面端体验零影响
   ============================================================ */

/* ---------- 1. 窄屏: 文件树抽屉化 ----------
   桌面端: 树正常显示; 窄屏: 默认隐藏, 点左缘把手展开
   body.darra-narrow-tree 由 JS 切换 (GitLab 19.2: aside[data-testid="project-page-sidebar"])
   ⚠ 此规则为注入覆盖 (GitLab 原生树窄屏下可能自身固定), 必须 !important */
@media (max-width: 800px) {
  aside[data-testid="project-page-sidebar"],
  .project-page-sidebar {
    position: fixed !important;
    top: 48px;
    left: 0;
    bottom: 0;
    width: min(78vw, 300px);
    z-index: 1060;
    overflow-y: auto;
    background: var(--gl-background-color-base, #fff);
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.15);
    transform: translateX(-102%);
    transition: transform 0.18s ease;
    border-radius: 0 6px 6px 0;
    padding-bottom: 40px;
    max-height: none !important;
  }
  body.darra-narrow-tree aside[data-testid="project-page-sidebar"],
  body.darra-narrow-tree .project-page-sidebar {
    transform: translateX(0);
  }
  /* 左缘把手 (由 JS 生成, 替代手机 FAB; 无遮罩, 树与内容同屏)
     display 不加 !important: JS 在无文件树页面设 inline display:none 需能覆盖 */
  #darra-tree-handle {
    display: inline-flex;
    position: fixed;
    left: 0;
    top: 52px;
    z-index: 1070;
    width: 18px;
    height: 44px;
    border-radius: 0 6px 6px 0;
    align-items: center;
    justify-content: center;
    background: #1e90ff;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
    border: none;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
  }
  #darra-tree-handle:hover { background: #1878d6; }
  body.darra-narrow-tree #darra-tree-handle {
    left: min(78vw, 300px);
    border-radius: 0 6px 6px 0;
  }
}
@media (min-width: 801px) {
  #darra-tree-handle { display: none; }
}

/* ---------- 2. 窄屏: 仓库内容区最大化, 侧栏让位 ----------
   树抽屉化后内容区自然恢复全宽; 这里只做轻量紧凑化,
   不动流水线状态等核心徽标 */
@media (max-width: 800px) {
  /* 项目元信息 (commits/branches/tags) 紧凑化 */
  .project-statistics .nav-links li {
    padding: 6px 8px !important;
  }
  .project-statistics .number {
    font-size: 0.95rem !important;
  }
  /* 隐藏非核心 DOM: 装饰性区块, 减渲染负担 */
  .project-last-activity {
    display: none !important;
  }
}

/* ---------- 3. 窄屏: 代码/表格横向滚动, 不撑破页面 ---------- */
@media (max-width: 800px) {
  .content .blob-content-holder,
  .content .diff-content,
  .content .table-responsive,
  .gl-table-wrap,
  .tree-holder,
  .content .file-content {
    overflow-x: auto !important;
    max-width: 100%;
  }
  .content .file-content pre,
  .content pre.code,
  .blob-content-holder pre {
    font-size: 12px;
    line-height: 1.45;
    padding: 8px;
    white-space: pre;
  }
  .gl-table {
    min-width: max-content;
  }
}

/* ---------- 4. 窄屏: 顶部导航简化 ----------
   GitLab 19.2 用 super-topbar (自带窄屏折叠: 汉堡 + 搜索 + 头像),
   这里再收掉非核心入口 (新建菜单 + 分隔), 只留 搜索 + 仓库名 + 头像 */
@media (max-width: 800px) {
  .super-topbar [data-testid="new-menu-toggle"],
  .super-topbar .gl-border-r {
    display: none !important;
  }
  .page-title h1,
  .page-title .title,
  [data-testid="page-title"] {
    font-size: 1.1rem !important;
  }
  /* 面包屑: GitLab 19.2 自带省略折叠 (显示更多), 不做二次隐藏 */
}

/* ---------- 5. 窄屏: 页脚隐藏 (嵌入场景无意义, 减滚动距离) ---------- */
@media (max-width: 800px) {
  .footer,
  .gl-footer,
  .footer-message,
  #footer {
    display: none !important;
  }
}

/* ---------- 6. 加载骨架屏 (性能 UX) ----------
   html.darra-boot 时内容区显示 shimmer 占位, JS 在内容就绪后移除 */
html.darra-boot .content aside[data-testid="project-page-sidebar"],
html.darra-boot .content .tree-holder,
html.darra-boot .content .gl-table,
html.darra-boot .content .blob-content-holder {
  position: relative;
  color: transparent !important;
  overflow: hidden;
  background: #ececec !important;
  border-radius: 4px;
  min-height: 120px;
}
html.darra-boot .content aside[data-testid="project-page-sidebar"]::after,
html.darra-boot .content .tree-holder::after,
html.darra-boot .content .gl-table::after,
html.darra-boot .content .blob-content-holder::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.55) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: darra-shimmer 1.1s infinite;
}
@keyframes darra-shimmer {
  100% { transform: translateX(100%); }
}
/* 骨架屏期间压住下方交互 */
html.darra-boot .content {
  pointer-events: none;
}

/* ---------- 7. 通用: 图片/头像懒加载淡入 ---------- */
img[data-darra-lazy] {
  opacity: 0;
  transition: opacity 0.25s ease;
}
img[data-darra-lazy].darra-lazy-loaded {
  opacity: 1;
}
