/* 三栏布局 */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;     /* 移动端兜底：动态视口高度 */
  overflow: hidden;
  position: relative;
}

/* 蒙层：仅移动端且导航打开时显示 */
#nav-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  z-index: 80;
}

/* 图标栏 */
#iconbar {
  width: 64px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 0;
  flex-shrink: 0;
  z-index: 100;
}
.iconbar-top, .iconbar-bottom {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
  position: relative;
}
.icon-btn:hover { background: #fff; color: var(--primary); }
.icon-btn.active { background: var(--primary-bg); color: var(--primary); }
.icon-btn.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

/* 左侧栏 */
#sidebar {
  width: 320px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .2s, opacity .2s;
  overflow: hidden;
  z-index: 90;
}
/* PC 收起状态 */
body.sidebar-closed #sidebar { width: 0; border-right: 0; }

.sidebar-header {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
  flex-shrink: 0;
}
.breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  font-size: 13px;
}
.breadcrumb a { color: var(--text-2); cursor: pointer; white-space: nowrap; }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb a.cur { color: var(--text); font-weight: 600; }
.breadcrumb .sep { color: var(--text-3); }
#btn-collapse {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--text-2);
  flex-shrink: 0;
}
#btn-collapse:hover { background: var(--bg-2); }
.sidebar-toolbar {
  padding: 8px 12px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-toolbar button {
  flex: 1;
  height: 32px;
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
}
.sidebar-toolbar button:hover { background: var(--primary-bg); color: var(--primary); }
#filelist {
  flex: 1;
  overflow-y: auto;
}

/* 右侧预览 */
#viewer {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.viewer-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  gap: 8px;
}
.viewer-empty .icon { width: 48px; height: 48px; color: var(--text-3); opacity: .5; }
.viewer-empty-title { font-size: 16px; color: var(--text-2); }
.viewer-empty-sub { font-size: 13px; }

/* ============ 移动端 ============ */
@media (max-width: 768px) {
  /* 图标栏：左侧竖排，默认隐藏，导航打开时滑入 */
  #iconbar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 64px;
    /* 关键修复 1：删除 height: 100vh，避免移动 Chrome 地址栏导致溢出 */
    max-height: 100dvh;
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: 2px 0 8px rgba(15, 23, 42, .06);
    z-index: 100;
    overflow-y: auto;
  }
  body.mobile-nav-open #iconbar { transform: translateX(0); }

  /* 左栏：从图标栏右侧滑入，右侧必须留出蒙层可点击区 */
  #sidebar {
    position: fixed;
    top: 0;
    left: 64px;
    bottom: 0;
    /* 关键修复 2：宽度上限 = min(320px, 100vw - 图标栏64 - 蒙层至少56) */
    width: min(calc(100vw - 64px - 56px), 320px);
    max-width: calc(100vw - 64px - 56px);
    max-height: 100dvh;
    background: #fff;
    transform: translateX(calc(-100% - 64px));
    transition: transform .2s;
    border-right: 1px solid var(--line);
    z-index: 90;
    overflow-y: auto;
  }
  body.mobile-nav-open #sidebar { transform: translateX(0); }

  /* 移动端不显示左栏收起按钮（用蒙层关闭） */
  #btn-collapse { display: none; }

  /* 移动端忽略 sidebar-closed 状态 */
  body.sidebar-closed #sidebar {
    width: min(calc(100vw - 64px - 56px), 320px);
    max-width: calc(100vw - 64px - 56px);
    border-right: 1px solid var(--line);
  }

  /* 导航打开时显示蒙层（z-index 80 < 左栏90 < 图标栏100，右侧空白区域可点击关闭） */
  body.mobile-nav-open #nav-mask { display: block; }

  /* 右侧预览区占满剩余宽度 */
  #viewer { width: 100%; }
}