/* layout.css — 应用骨架与三档响应式导航
 *
 * 红线三硬约束：
 *   * 三档导航严格互斥：任一视口只渲染 / 只显示一套
 *       < 768px       底部毛玻璃 TabBar
 *       768 ~ 1023px  顶部居中 Segmented Control
 *       >= 1024px     左侧 Things 3 风格固定侧栏
 *   * 顶栏左右等宽占位，标题水平绝对居中
 *   * 主内容区卡片硬防溢出（min-width: 0 + 折行保护）
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", Arial, sans-serif;
  font-size: var(--font-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── 应用骨架 ─────────────────────────────────────────── */

.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

.app__body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.app__main {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-6) + var(--safe-bottom));
}

.app__content,
#view {
  min-width: 0;
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

/* ── 顶栏：标题绝对居中（左右使用等宽 1fr 占位） ─────── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-2);
  height: var(--header-height);
  padding: 0 var(--space-4);
  padding-top: var(--safe-top);
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.app-header__left {
  grid-column: 1;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.app-header__title {
  grid-column: 2;
  justify-self: center;
  margin: 0;
  font-size: var(--font-lg);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.app-header__right {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

/* ── 导航：默认全部隐藏，由三档媒体查询各自启用 ─────── */

.nav-sidebar,
.nav-segmented,
.nav-tabbar {
  display: none;
}

.nav-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 档位一：< 768px 底部毛玻璃 TabBar ───────────────── */

@media (max-width: 767px) {
  .nav-tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    height: calc(var(--tabbar-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: color-mix(in srgb, var(--chrome) 88%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--line);
  }

  .nav-tabbar__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--tap-min);
    min-width: 0;
    color: var(--text-3);
    font-size: var(--font-xs);
    text-decoration: none;
  }

  .nav-tabbar__item[aria-current="page"] {
    color: var(--brand);
  }

  /* 给底部导航让出空间，避免卡片贴底 */
  .app__main {
    padding-bottom: calc(var(--tabbar-height) + var(--space-6) + var(--safe-bottom));
  }
}

/* ── 档位二：768 ~ 1023px 顶部居中 Segmented ─────────── */

@media (min-width: 768px) and (max-width: 1023px) {
  .nav-segmented {
    display: flex;
    gap: var(--space-1);
    margin: var(--space-3) auto 0;
    padding: var(--space-1);
    width: calc(100% - var(--space-8));
    max-width: 560px;
    background: var(--surface-2);
    border-radius: var(--radius-pill);
  }

  .nav-segmented__item {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap-min-dense);
    min-width: 0;
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    color: var(--text-2);
    font-size: var(--font-sm);
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out),
      color var(--dur-fast) var(--ease-out);
  }

  .nav-segmented__item[aria-current="page"] {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-card);
  }
}

/* ── 档位三：>= 1024px 左侧栏 ───────────────────────── */

@media (min-width: 1024px) {
  .nav-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    padding: var(--space-6) var(--space-4);
    padding-bottom: calc(var(--space-6) + var(--safe-bottom));
    background: var(--surface-2);
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
  }

  .nav-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0 var(--space-3) var(--space-4);
    font-size: var(--font-base);
    font-weight: 700;
    color: var(--text);
  }

  .nav-sidebar__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--tap-min);
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-2);
    font-size: var(--font-base);
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out);
  }

  .nav-sidebar__item:hover {
    background: var(--surface-3);
  }

  .nav-sidebar__item[aria-current="page"] {
    background: var(--brand-soft);
    color: var(--brand-text);
    font-weight: 600;
  }

  /* 宽屏下顶栏只在主栏内，标题仍居中于主栏 */
  .app__main {
    padding: var(--space-6) var(--space-8);
  }

  .app__content,
  #view {
    max-width: var(--content-max-width);
  }
}
