/* 基础层：重置、排版、应用外壳、顶部导航、底部导航。
   按 @layer 分层，后面加页面样式永远不用 !important 去打架。 */

@layer tokens, base, components, pages;

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

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

  body {
    margin: 0;
    background: var(--bg-out);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
      "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

  button,
  input,
  textarea,
  select {
    font: inherit;
    color: inherit;
  }

  button {
    border: 0;
    background: none;
    padding: 0;
    cursor: pointer;
  }

  p {
    margin: 0;
  }

  /* 应用外壳：手机上一列到底；平板起铺满屏幕（--max 只用来兜住手机）
     以前平板也卡在 640，两侧露 --bg-out 的灰边，横屏看就像没适配 */
  .app {
    max-width: var(--max);
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
  }

  .main {
    flex: 1;
    min-width: 0;
    padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
  }

  .main.flush {
    padding-bottom: 0;
  }

  /* ---- 顶部导航 ---- */
  .nav {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 18px var(--gutter) 14px;
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 20;
  }

  .nav-title {
    /* 占住中间的空位：导航只有「返回 + 标题」时标题不会被 space-between 顶到最右 */
    flex: 1;
    font-size: 16px;
    font-weight: 500;
    letter-spacing: -0.2px;
  }

  .nav-sub {
    font-size: 11px;
    color: var(--text-3);
  }

  /* 返回：放在 .nav 里的行内元素，不单独占一条 */
  .back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-2);
    min-height: var(--tap);
    max-width: 72%;
    overflow: hidden;
    white-space: nowrap;
  }

  .back .chev {
    font-size: 17px;
    line-height: 1;
    color: var(--text-2);
    flex-shrink: 0;
  }

  .nav-act {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-3);
    padding: 6px 0 6px 10px;
    min-height: var(--tap);
    display: flex;
    align-items: center;
  }

  .nav-act.strong {
    color: var(--text);
  }

  .nav-act.danger {
    color: var(--danger);
  }

  /* 导航里的表单包裹（如编辑页的删除），顶到最右，跟 .nav-act 行为一致 */
  .nav-del {
    margin-left: auto;
    display: flex;
    align-self: center;
  }

  /* ---- 底部导航 ---- */
  .tabbar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max);
    display: flex;
    align-items: flex-end;
    padding: 9px 0 calc(12px + var(--safe-b));
    background: var(--bg);
    border-top: 1px solid var(--line);
    z-index: 30;
  }

  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-3);
    font-size: 11px;
    min-height: var(--tap);
    justify-content: flex-end;
    padding-bottom: 2px;
  }

  .tab.on {
    color: var(--text);
  }

  .tab-mid {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-end;
  }

  .tab-mid button {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    margin-bottom: 2px;
  }

  /* 底部导航是唯一的导航：手机、平板竖屏、平板横屏都显示它。
     以前 1024 起就隐藏，横屏只剩顶部标题，等于没有入口 */
  @media (min-width: 768px) {
    body {
      background: var(--bg-out);
    }
    .app,
    .tabbar {
      max-width: none;
    }
  }
}
