/* layout.css — 三端外壳与 Grid 列数
 *
 * 铁律：
 * 1. 断点只有 679 / 680 与 1023 / 1024，禁止 767 / 768。
 * 2. 高度用 100dvh（100vh 兜底），顶栏吃 safe-area-inset-top，TabBar 与吸底栏吃 bottom。
 * 3. 顶栏高度恒定；条件工具条放页内，不塞进 header，避免切页整页上跳。
 * 4. 抽屉打开时锁死底层滚动，用 overflow 锁定 + scrollbar-gutter 保证零横向跳动。
 */

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

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

html.sheet-open,
html.sheet-open body {
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  touch-action: manipulation;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.app {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* 桌面侧栏：1024 起才出现 */
.sidebar {
  display: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: calc(var(--bar-h) + var(--safe-top));
  padding: var(--safe-top) var(--space-4) 0;
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}

.topbar__title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 平板（680–1023）用紧凑分段切视图；手机靠 TabBar，桌面靠侧栏 */
.topbar__views {
  display: none;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.topbar__views .segmented__btn {
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

/* 顶栏右侧动作区：搜索 / 排序 / 新建 */
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: auto;
}

.topbar__filter {
  flex: 0 0 auto;
}

.topbar__spacer {
  flex: 1;
}

.topbar__seg {
  display: none;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

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

/* 手机：标题居中，左右各留一个动作位 */
@media (max-width: 679px) {
  .topbar {
    gap: var(--space-2);
  }

  .topbar__title {
    flex: 1;
    text-align: center;
    font-size: var(--text-base);
  }

  .topbar__actions {
    margin-left: 0;
  }
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
}

/* 手机底部毛玻璃 TabBar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding: 0 var(--space-2) var(--safe-bottom);
  padding-left: calc(var(--space-2) + var(--safe-left));
  padding-right: calc(var(--space-2) + var(--safe-right));
  background: var(--blur-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}

.tabbar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: var(--text-2xs);
  cursor: pointer;
}

.tabbar__item.is-active {
  color: var(--accent);
}

.tabbar__icon {
  display: block;
  width: 24px;
  height: 24px;
}

/* iPad 竖屏：2 列 */
@media (min-width: 680px) {
  .tabbar {
    display: none;
  }

  .main {
    padding: var(--space-5) var(--space-6) var(--space-8);
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .topbar__views {
    display: flex;
    margin-left: var(--space-3);
  }
}

/* iPad 横屏 / Mac：侧栏 + 3 列 */
@media (min-width: 1024px) {
  .app {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
    height: 100vh;
    height: 100dvh;
    padding: calc(var(--safe-top) + var(--space-5)) var(--space-3) var(--space-4);
    border-right: 1px solid var(--line);
    background: var(--bg);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .topbar__seg {
    display: none;
  }

  .main {
    padding: var(--space-6) var(--space-8) var(--space-8);
    max-width: 1320px;
  }

  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
  }

  /* 宽屏侧栏常驻，不再需要顶栏筛选按钮与视图切换（提高特异性压过 .icon-btn） */
  .topbar .topbar__filter {
    display: none;
  }

  .topbar__views {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
