/* layout.css - 应用骨架：顶栏、主区、底部导航、响应式（360 像素起） */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--color-bg);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.app-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
}

/* App 壳模式（WebView 内以 ?app=1 打开）：隐藏顶部横幅；网页版无 mode-app 类，不受影响 */
.mode-app .app-header,
html.mode-app .app-header {
  display: none;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.app-subtitle {
  font-size: 0.82rem;
  color: var(--color-text-soft);
}

#engine-banner {
  display: none;
  align-items: flex-start;
  gap: 0.5rem;
  background: #fff4e0;
  color: var(--color-warn);
  border-bottom: 1px solid #f0d9ad;
  padding: 0.6rem 1rem;
  font-size: 0.92rem;
}

#page-container {
  flex: 1;
  /* BUG-4: 底部 padding 等于底栏高度加安全区，滚动到底时内容不被底栏压住 */
  padding: 1rem 1rem calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom));
  /* BUG-4: 容器自身若出现内部滚动，同样为底栏留出滚动内边距 */
  scroll-padding-bottom: calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom));
  overflow-y: auto;
}

#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  /* BUG-4: z-index 高于内容层，遮挡关系明确 */
  z-index: 30;
  display: flex;
  justify-content: space-around;
  /* BUG-4: 背景必须不透明（--color-surface 为 #ffffff），内容不得从底栏透出 */
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0;
  color: var(--color-text-soft);
  font-size: 0.8rem;
  text-decoration: none;
}

.nav-item:hover { text-decoration: none; }

.nav-active {
  color: var(--color-primary);
  font-weight: 600;
}

@media (min-width: 721px) {
  .app-shell {
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    min-height: 100vh;
  }
  #bottom-nav { border-left: 1px solid var(--color-border); border-right: 1px solid var(--color-border); }
}

/* 小屏断点：兼容 360 像素宽度（含 320-400 像素窄屏） */
@media (max-width: 400px) {
  .app-header { padding: 0.55rem 0.75rem; }
  .app-title { font-size: 1.02rem; }
  .app-subtitle { font-size: 0.78rem; }
  /* BUG-4: 小屏同样保留底栏高度加安全区的底部避让 */
  #page-container { padding: 0.75rem 0.75rem calc(var(--bottom-nav-clearance) + env(safe-area-inset-bottom)); }
  .card { padding: 0.85rem 0.75rem; }
  .page-title { font-size: 1.28rem; }
  .card-actions .btn { flex: 1 1 100%; }
  .card-actions .btn-sm { flex: 1 1 auto; }
  .stat-row { gap: 0.4rem; }
  .stat-value { font-size: 1.08rem; }
  .quick-grid { gap: 0.5rem; }
  .quick-label { font-size: 0.84rem; }
  .q-stem { font-size: 1.05rem; }
  .word-big { font-size: 1.25rem; }
  .dim-name { width: 70px; font-size: 0.88rem; }
  .dim-val { width: 52px; font-size: 0.85rem; }
  .device-code { font-size: 1.12rem; letter-spacing: 0.04em; word-break: break-all; }
  .modal-box { max-width: 96vw; padding: 1rem 0.85rem; }
  .rate-row { flex-wrap: wrap; }
  .btn-rate { flex: 1 1 42%; min-width: 0; }
  .tab-row { gap: 0.4rem; }
  .nav-label { font-size: 0.72rem; }
  .trace-row { flex-wrap: wrap; }
}

/* 超窄屏兜底（320 像素级） */
@media (max-width: 340px) {
  #page-container { padding-left: 0.55rem; padding-right: 0.55rem; }
  .card { padding: 0.75rem 0.55rem; }
  .app-logo { width: 28px; height: 28px; font-size: 0.95rem; }
}
