/* ═══════════════════════════════════════════════════════════════
   糧好生活 · 元件
   ═══════════════════════════════════════════════════════════════ */

/* ── 卡片 ─────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--r); padding: 14px 16px; box-shadow: var(--lift);
}
.card.flat { box-shadow: none; }
.card.warm { background: var(--warm-soft); border-color: var(--warm); border-style: dashed; }
.card.calm { background: var(--calm-soft); border-color: var(--calm); }

/* ── 按鈕 ─────────────────────────────────────────────── */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 700; background: var(--surface); border: 2px solid var(--line);
  box-shadow: var(--lift); transition: transform var(--ease), border-color var(--ease);
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: var(--lift-pop); }
.btn.soft    { background: var(--accent-soft); color: var(--accent-deep); border-color: transparent; }
.btn.ghost   { background: transparent; border-color: var(--line); box-shadow: none; color: var(--ink-soft); }
/* 破壞性動作用文字＋圖示明說，不只用紅色 */
.btn.danger  { background: var(--surface); color: var(--accent-deep); border-color: var(--accent); box-shadow: none; }
.btn.block   { width: 100%; }
/* 版面吃緊的地方用的小按鈕：字小、留白少，但高度還是 44px。
   ⚠️ 原本是用 ::after { inset: -6px } 撐觸控範圍，實測不可靠 ——
   同樣的寫法在 .viewswitch 上有效（45px），在這裡卻只有 41px，
   放在 .sect 標題列裡的甚至完全沒效果（34px）。
   周圍的版面會不會讓那一層被蓋掉，是看不出來的。
   **真實高度才是保證，透明層只是招數。**
   要用透明層的地方，一定要用 document.elementFromPoint 實際打一次確認。 */
.btn.mini    { min-height: var(--tap); padding: 0 14px; font-size: var(--fs-tiny); }
.btn:disabled { opacity: .45; }

/* 只有圖示的方形按鈕（＋ － ↑ ↓ ⋯）一律 44×44 起 */
.iconbtn {
  width: var(--tap); height: var(--tap); flex: 0 0 var(--tap);
  display: grid; place-items: center; border-radius: var(--r-sm);
  background: var(--surface-sunk); color: var(--accent-deep); font-size: 19px; font-weight: 700;
  border: 1.5px solid var(--line); transition: transform var(--ease);
}
.iconbtn:active { transform: scale(.9); }
.iconbtn:disabled { opacity: .35; }

/* ── 輸入 ─────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: var(--fs-small); font-weight: 700; color: var(--ink-soft); padding-left: 4px; }
.input, .select {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  border: 2px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
}
.input:focus, .select:focus { border-color: var(--accent); outline: none; }
.input::placeholder { color: var(--ink-faint); }
/* 圓角搜尋框，固定在畫面上方時捲動不消失（spec 6-4） */
.searchbox { position: relative; }
.searchbox .input { padding-left: 44px; border-radius: var(--r-pill); box-shadow: var(--lift-warm); }
.searchbox .ic { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 16px; }

/* ── 狀態標示 ── spec 6-1 ─────────────────────────────────
   三重標示：底色 + 圖示 + 中文字。少任何一重都不合格。
   已過期用實心、其餘用外框 —— 連形狀都不一樣，掃視時最快分辨。 */
.stat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--r-pill);
  font-size: var(--fs-tiny); font-weight: 700; white-space: nowrap;
  border: 1.5px solid transparent;
}
.stat .ic { font-size: 11px; }

/* emoji 一律走這個 class：專用字型 + 固定行高，
   不然不同 emoji 的高度不一，整行的基線會跳。 */
.emo, .sect h2 .dot, .menu button .ic, .tabbar button .ic, .prepbanner .e, .rcard .e {
  font-family: var(--font-emoji); font-style: normal; line-height: 1;
  display: inline-block; vertical-align: -0.1em;
}
.stat.expired { background: var(--st-expired-fg); color: #fff; }
.stat.soon    { background: var(--st-soon-bg);  color: var(--st-soon-fg);  border-color: var(--st-soon-fg); }
.stat.watch   { background: var(--st-watch-bg); color: var(--st-watch-fg); border-color: var(--st-watch-fg); }
.stat.note    { background: var(--st-note-bg);  color: var(--st-note-fg); }
.stat.safe    { background: var(--st-safe-bg);  color: var(--st-safe-fg); }
.stat.none    { background: var(--st-none-bg);  color: var(--st-none-fg); border-style: dashed; border-color: var(--st-none-fg); }

/* ── 列表列 ───────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: var(--gap-list); }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 2px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 10px 8px 14px; box-shadow: var(--lift);
}
.item .name { font-weight: 700; }
.item.nested { margin-left: 18px; background: var(--surface-sunk); box-shadow: none; }

/* ── 分組（可展開收合）─────────────────────────────────── */
.group { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r); box-shadow: var(--lift); overflow: hidden; }
.group > summary {
  min-height: var(--tap); padding: 10px 14px; display: flex; align-items: center; gap: 8px;
  cursor: pointer; list-style: none; font-weight: 700;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: '▾'; margin-left: auto; color: var(--ink-soft); transition: transform var(--ease); }
.group[open] > summary::after { transform: rotate(180deg); }
.group > summary .count { font-size: var(--fs-tiny); font-weight: 400; color: var(--ink-soft); }
.group .body { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 8px; }

/* ── 空狀態：一定要給一條路走 ─────────────────────────── */
.empty { text-align: center; padding: 34px 20px; color: var(--ink-soft); }
.empty .e { font-size: 40px; margin-bottom: 8px; }
.empty p { margin-bottom: 14px; font-size: var(--fs-body); line-height: 1.8; }

/* ── 浮層（sheet）：從底部長出來，操作在拇指區 ──────────── */
.scrim {
  position: fixed; inset: 0; z-index: 50; background: rgba(75, 59, 51, .38);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 480px; background: var(--bg);
  border-radius: var(--r) var(--r) 0 0; padding: 18px var(--pad) calc(18px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto; animation: rise .22s cubic-bezier(.2, .9, .3, 1);
  box-shadow: 0 -8px 30px -12px rgba(75, 59, 51, .4);
}
.sheet h2 { font-family: var(--font-hand); font-size: 21px; color: var(--accent-deep); font-weight: 400; margin-bottom: 4px; }
.sheet .desc { font-size: var(--fs-small); color: var(--ink-soft); margin-bottom: 14px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet .actions .btn { flex: 1; }
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

/* ── 提示條 ─────────────────────────────────────────────
   這些是整句話不是標籤，所以用內文字級。
   離線橫幅尤其重要 —— 斷網時它是唯一的說明。 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 14px); z-index: 60;
  max-width: min(88vw, 440px);
  background: var(--ink); color: #fff; border-radius: var(--r-pill);
  padding: 11px 18px; font-size: var(--fs-body); box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .45);
  display: flex; align-items: center; gap: 12px; animation: rise .2s ease;
}
/* 「復原 / 撤銷」是全 App 最重要的一顆按鈕（扣庫存、回填、刪除都靠它反悔），
   而且只出現幾秒鐘 —— 按不到就等於沒有。視覺維持小字，用透明的 ::after
   把實際觸控範圍撐到 44px 以上，提示條的外觀完全不變。 */
.toast button {
  color: var(--raw-berry-soft); font-weight: 700; text-decoration: underline;
  white-space: nowrap; position: relative;
}
.toast button::after { content: ''; position: absolute; inset: -11px -12px; }

/* ── 通行碼閘門 ───────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; overflow-y: auto;
}
.gate .logo { font-family: var(--font-hand); font-size: 40px; color: var(--accent-deep); letter-spacing: 3px; }
.gate .logo b { color: var(--warm); font-weight: 400; }
.gate .tag { color: var(--ink-soft); font-size: var(--fs-small); margin-top: 2px; letter-spacing: 2px; }
.gate form, .gate .panel { width: 100%; max-width: 320px; margin-top: 26px; display: flex; flex-direction: column; gap: 12px; }
.gate .err { color: var(--accent-deep); font-size: var(--fs-small); background: var(--accent-soft); border-radius: var(--r-sm); padding: 10px 14px; text-align: left; }
.gate .note { font-size: var(--fs-tiny); color: var(--ink-soft); margin-top: 20px; max-width: 320px; line-height: 1.6; text-align: left; }
.gate .who { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gate .who .btn { min-height: 56px; }

/* ── 離線／狀態橫幅 ── spec 11-4 ────────────────────────── */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: var(--r-sm); font-size: var(--fs-body); line-height: 1.7;
  margin-bottom: var(--gap); border: 2px solid transparent;
}
.banner.offline { background: var(--st-none-bg); color: var(--ink); border-color: var(--ink-soft); border-style: dashed; }
.banner.info    { background: var(--warm-soft); color: var(--warm-deep); border-color: var(--warm); }
.banner.ok      { background: var(--calm-soft); color: var(--calm-deep); border-color: var(--calm); }
.banner .ic { font-size: 17px; }

/* ── 建置中的分頁 ───────────────────────────────────────
   class 叫 .notyet 不叫 .soon：.soon 已經被效期狀態用掉了，
   撞名會讓「快過期」的小標籤吃到這裡的 padding 變成一顆大圓球。 */
.notyet { text-align: center; padding: 30px 18px; }
.notyet .e { font-size: 46px; }
.notyet h2 { font-family: var(--font-hand); font-size: 22px; color: var(--accent-deep); font-weight: 400; margin: 8px 0 6px; }
.notyet p { font-size: var(--fs-small); color: var(--ink-soft); }
.notyet ul { text-align: left; margin: 16px auto 0; max-width: 320px; font-size: var(--fs-small); color: var(--ink-soft); padding-left: 20px; }
.notyet ul li { margin-bottom: 5px; }

/* ── 設定頁的分組列表 ─────────────────────────────────── */
.menu { display: flex; flex-direction: column; gap: var(--gap-list); }
.menu button {
  min-height: 58px; display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 14px; box-shadow: var(--lift); transition: transform var(--ease);
}
.menu button:active { transform: scale(.985); }
.menu button .ic { font-size: 22px; width: 30px; text-align: center; }
.menu button .t { font-weight: 700; }
.menu button .s { font-size: var(--fs-tiny); color: var(--ink-soft); }
.menu button .go { margin-left: auto; color: var(--ink-faint); font-size: 18px; }

/* 自我檢查的結果列 */
.check { display: flex; gap: 10px; align-items: flex-start; font-size: var(--fs-body); padding: 8px 0; border-bottom: 1px dashed var(--line); }
.check:last-child { border-bottom: none; }
.check .m { flex: 1; }
.check .r { font-weight: 700; white-space: nowrap; }
.check code { font-size: var(--fs-tiny); background: var(--surface-sunk); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
