/*
 * 底部導航欄的樣式（意見 #39／#26：「现在那些功能都太难找了，我打算参考微信」）。
 *
 * ── 為什麼是**獨立的一支檔案**，而不是留在 `app.css` 裡 ──────────
 *
 * 與 `_bottomnav.php` 同一個理由：底欄要出現在**兩套互不相干的版面**上
 *   · `_shell.php`（萬聖節／通話／API key／回放／我的）—— 載 `app.css`
 *   · `public/drive/_app.php`（雲盤的七頁）—— **只載 `drive.css`**
 *
 * 而這段規則原本住在 `app.css` 裡 ⇒ 雲盤頁**完全沒有底欄樣式**：
 * 底欄退化成文件流裡的一排 `<a>`（實測 390px 視口下 `position: static`、
 * `366×36`、`display: inline`），跑到頁面最下面（`y≈1934`），
 * 而且高度 36px < 44px 的觸控最小可點尺寸。
 *
 * ⚠ 這正是 `AGENTS.md`「搬了 HTML 沒帶走 CSS ⇒ 安靜死碼」的反面：
 *   `_bottomnav.php` 在 2026-10-16 被抽出來共用，**CSS 留在原地**，
 *   於是那一頁「有底欄但看不出來是底欄」，而且**沒有任何錯誤訊息**。
 *   被 `drive-touch-audit.mjs` 的觸控稽核抓到（8 條紅）。
 *
 * ⇒ 兩邊都 `<link>` 這一支。**只有一份實作**。
 * ⚠ 載入順序要在 `app.css`／`drive.css` **之後**（它含 `@media` 覆寫）。
 */

/* ══════════════════════════════════════════════════════════════════════════
 * 底部導航欄（意見 #39／#26：「现在那些功能都太难找了，我打算参考微信」）
 *
 * ⚠ 為什麼在檔案**最尾端**：它是 `@media (max-width: 720px)` 的覆寫。
 *   AGENTS.md §20 那條「同特異度的 CSS 後出現的勝，而錯誤是靜默的」——
 *   寫在基礎規則之前的話，量到的還是舊值，而畫面上不會有任何提示。
 *   放在最後是唯一不需要逐條追行號的做法。
 *
 * ⚠ 桌機版**完全不顯示**：側欄一直都在，第二份導覽只會分散注意力。
 * ══════════════════════════════════════════════════════════════════════════ */
/*
 * ⚠⚠ **高度只有這一個住處**（第 488 輪）。
 *
 * 舊版把 `--tabbar-h: 56px` 寫在 `app.css` 的 `@media (max-width: 600px)` 裡面，
 * 而底欄真正的斷點是 720px（下面就這一支）⇒ 601–720px 之間「有底欄、沒留白」。
 * 現在這個 token 住在**實作它的那一支檔案**裡，兩個消費者
 * （`bottomnav.css` 自己的留白、`app.css` 的 `.app`）都讀它。
 * 聊天室那一頁不載 bottomnav.css ⇒ 消費者一律寫 `var(--bottomnav-h, 56px)`。
 */
:root { --bottomnav-h: 56px; }

.ui-bottomnav { display: none; }

@media (max-width: 720px) {
  /* 底欄是 position:fixed ⇒ 一定要留出等高的底部空間，
     否則畫面上**最後一條訊息**永遠被它蓋住（而捲到底也看不到）。 */
  /*
   * ⚠ 不是 `body.ui` —— 實測各頁的 `<body class>` 是 **四種**：
   *   `ui`（apikey／replay／profile）、`d-body`（雲盤）、
   *   `hw-page is-halloween`（萬聖節）、`call-page`（通話）。
   *   只寫 `body.ui` 的話，**只有三頁**留了底部空間，其餘三頁的
   *   最後一條內容永遠被底欄蓋住 —— 而捲到底也看不到，因為那不是捲動問題。
   * ⇒ 用 `:has()` 問「這一頁有沒有底欄」，那是唯一跨版面的判準。
   */
  /*
   * ⚠⚠ `:not(:has(.app))` 不是裝飾（第 488 輪）：聊天室的版面是
   *   `.app { height: 100dvh }` 的 grid，留白必須加在**它自己**身上
   *   （`app.css` 的 `body:has(.ui-bottomnav) .app`）。兩邊都加的話
   *   body 會多出 56px ⇒ 整頁可以往下捲 56px ⇒ 往下捲時標頭被推出畫面。
   */
  body:not(:has(.app)):has(.ui-bottomnav) {
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  }

  .ui-bottomnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;               /* 高於側欄（30）、低於 modal（100＋） */
    margin: 0;
    padding: 0 0 env(safe-area-inset-bottom, 0px);
    background: var(--surface, #fff);
    border-top: 1px solid var(--line, #e5e7eb);
    box-shadow: 0 -1px 8px rgba(0, 0, 0, .06);
  }

  .ui-bottomnav-item {
    /* 紅點的定位基準（見下面的 `.ui-bottomnav-dot`）。 */
    position: relative;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    /* 44px 是觸控最小可點高度；56px（`--bottomnav-h`）讓文字＋圖示都放得下。 */
    min-height: var(--bottomnav-h);
    padding: 6px 2px;
    text-decoration: none;
    color: var(--text-dim, #6b7280);
    font-size: 10px;
    line-height: 1.2;
    -webkit-tap-highlight-color: transparent;
  }

  /*
   * 未讀紅點（意見 #26 第 11 項）。12px ＝ 微信那顆紅點在手機上的視覺重量；
   * 它**不可點**（`aria-hidden` ＋ `pointer-events:none`）—— 它標的是
   * 旁邊那一格，不是自己一個目標。
   */
  .ui-bottomnav-dot {
    position: absolute;
    top: 4px;
    left: 50%;
    margin-left: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e5484d;
    box-shadow: 0 0 0 2px var(--surface, #fff);
    pointer-events: none;
  }

  .ui-bottomnav-item.is-current { color: var(--accent, #2563eb); }

  .ui-bottomnav-ic { display: block; }
  /* 圖示 22px：與 iOS／微信底欄同一個量級（再大就和 10px 的文字不成比例）。 */
  .ui-bottomnav-ic .ic { width: 22px; height: 22px; }

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