/* 工作台响应式外壳（Phase 0 提供，Phase 1/3 逐页引入）
 *
 * 页面骨架：
 *   .app-shell[data-page]
 *     aside.app-sidebar#app-sidebar
 *     .app-body
 *       header.app-topbar#app-topbar
 *       main.app-content#app
 *     nav.app-bottomnav#app-bottomnav
 *
 * 依赖 ui.css 的 token 与组件；本文件只负责外壳布局。
 */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
}

/* hidden 属性优先于 display:grid（登录页与未登录视图共用） */
.app-shell[hidden] { display: none; }

/* ---------- 侧边栏（桌面） ---------- */

.app-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-2) var(--sp-4);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 700;
  text-decoration: none;
}

.app-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  color: #fff;
  background: var(--primary);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 700;
}

.app-class-picker {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  margin-bottom: var(--sp-4);
  background: var(--surface-2);
  border-radius: var(--r-md);
}

.app-class-picker .app-class-select {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 8px;
  font-size: var(--fs-sm);
}

.app-online-dot { width: 9px; height: 9px; }

.app-nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.app-nav-group + .app-nav-group { margin-top: var(--sp-4); }

.app-nav-title {
  padding: var(--sp-1) var(--sp-3);
  color: var(--text-3);
  font-size: var(--fs-xs);
  font-weight: 500;
}

.app-nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 42px;
  padding: 0 var(--sp-3);
  color: var(--text-2);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}

.app-nav-link .ui-icon { color: var(--text-3); }

.app-nav-link.is-on {
  color: var(--primary);
  background: var(--primary-weak);
  font-weight: 600;
}

.app-nav-link.is-on .ui-icon { color: var(--primary); }

.app-nav-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

@media (hover: hover) {
  .app-nav-link:hover { background: var(--surface-2); color: var(--text); }
  .app-nav-link.is-on:hover { background: var(--primary-weak); color: var(--primary); }
}

.app-sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: auto;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}

.app-user {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  padding: 0 var(--sp-2);
}

.app-user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  color: var(--primary);
  background: var(--primary-weak);
  border-radius: 50%;
}

.app-user-text { display: flex; flex-direction: column; min-width: 0; }

.app-user-name {
  overflow: hidden;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user-role { color: var(--text-3); font-size: var(--fs-xs); }

.app-sidebar-actions { display: flex; gap: var(--sp-1); }

.app-sidebar-actions .ui-btn { flex: 1; }

/* ---------- 主体 ---------- */

.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-content {
  width: 100%;
  max-width: 1200px;
  min-width: 0;
  margin: 0 auto;
  padding: var(--sp-5);
  flex: 1;
}

/* ---------- 页面通用结构 ---------- */

.app-page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.app-page-title {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: 1.3;
}

.app-page-sub {
  margin: 4px 0 0;
  color: var(--text-3);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.app-page-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr);
  gap: var(--sp-4);
  align-items: start;
}

.app-layout--even {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-layout-side { min-width: 0; }

.app-sticky {
  position: sticky;
  top: var(--sp-4);
}

.app-section-gap { margin-top: var(--sp-4); }

/* 手机端吸底主操作 */
.app-mobile-bar {
  display: flex;
  gap: var(--sp-2);
}

@media (max-width: 1199px) {
  .app-layout,
  .app-layout--even { grid-template-columns: minmax(0, 1fr); }

  .app-sticky { position: static; }
}

@media (max-width: 640px) {
  .app-page-head { margin-bottom: var(--sp-4); }

  .app-page-title { font-size: var(--fs-lg); }

  .app-mobile-bar {
    position: sticky;
    bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) +
                 var(--sp-2));
    z-index: 5;
    padding: var(--sp-2);
    margin: 0 calc(-1 * var(--sp-2));
    background: var(--bg);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-2);
  }

  .app-mobile-bar .ui-btn { flex: 1; }
}

/* 顶部栏默认隐藏，手机显示 */
.app-topbar { display: none; }

/* 底部 Tab 默认隐藏，手机显示 */
.app-bottomnav { display: none; }

/* ---------- 手机端 ---------- */

@media (max-width: 959px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
  }

  .app-sidebar { display: none; }

  .app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: var(--topbar-h);
    padding: 0 var(--sp-3);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .app-topbar-brand {
    flex: none;
    color: var(--text);
    font-size: var(--fs-base);
    font-weight: 700;
    white-space: nowrap;
  }

  .app-topbar .app-class-select {
    flex: 1;
    min-width: 0;
    min-height: 36px;
    padding: 5px 8px;
    font-size: var(--fs-sm);
  }

  .app-topbar-user {
    flex: none;
    max-width: 96px;
    overflow: hidden;
    color: var(--text-3);
    font-size: var(--fs-xs);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-content { padding: var(--sp-3); }

  .app-bottomnav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }

  .app-bottomnav-link {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    padding: 4px 2px;
    color: var(--text-3);
    background: transparent;
    border: 0;
    font: inherit;
    font-size: var(--fs-xs);
    text-decoration: none;
    cursor: pointer;
  }

  .app-bottomnav-link.is-on { color: var(--primary); }

  .app-bottomnav-link:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 3px var(--focus);
  }

  .app-bottomnav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ---------- 手机端「更多」抽屉 ---------- */

.app-more-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, .46);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease),
              visibility var(--dur) var(--ease);
}

.app-more-backdrop.is-open { opacity: 1; visibility: visible; }

.app-more-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 41;
  max-height: 80vh;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: 0 -8px 24px rgba(15, 23, 42, .16);
  visibility: hidden;
  transform: translateY(100%);
  transition: transform var(--dur) var(--ease),
              visibility var(--dur) var(--ease);
}

.app-more-sheet.is-open { visibility: visible; transform: none; }

.app-more-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.app-more-title {
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
}

.app-more-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
}

.app-more-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 72px;
  padding: var(--sp-2);
  color: var(--text-2);
  background: var(--surface-2);
  border: 0;
  border-radius: var(--r-md);
  font: inherit;
  font-size: var(--fs-xs);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.app-more-item .ui-icon { color: var(--text-3); }

.app-more-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

@media (hover: hover) {
  .app-more-item:hover { color: var(--text); background: var(--primary-weak); }
}

.app-more-foot {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.app-more-foot .ui-btn { flex: 1; }

@media (min-width: 960px) {
  .app-more-backdrop,
  .app-more-sheet { display: none; }
}
