/* ===== 配色（10 種） ===== */
:root, [data-theme="forest"] {
  --bg:#f3f8f4; --card:#ffffff; --text:#1d3427; --sub:#5b7566; --line:#dbe8df;
  --soft:#e3f1e8; --primary:#3f8f5f; --on-primary:#ffffff;
}
[data-theme="ocean"] {
  --bg:#f2f7fb; --card:#ffffff; --text:#14293d; --sub:#5a7389; --line:#d9e5ef;
  --soft:#e1eef9; --primary:#2f7fc1; --on-primary:#ffffff;
}
[data-theme="peach"] {
  --bg:#fdf4f5; --card:#ffffff; --text:#3d1d22; --sub:#8a5d63; --line:#f1dadd;
  --soft:#fbe5e8; --primary:#d9596b; --on-primary:#ffffff;
}
[data-theme="sunset"] {
  --bg:#fdf6ef; --card:#ffffff; --text:#3a2410; --sub:#86684c; --line:#f0e0cf;
  --soft:#fbebd9; --primary:#d9701d; --on-primary:#ffffff;
}
[data-theme="lavender"] {
  --bg:#f6f3fb; --card:#ffffff; --text:#251a3d; --sub:#6c5f88; --line:#e3dcf1;
  --soft:#ece6f8; --primary:#7a5bc2; --on-primary:#ffffff;
}
[data-theme="lemon"] {
  --bg:#fcfaee; --card:#ffffff; --text:#2f2a10; --sub:#7d7440; --line:#eee7c4;
  --soft:#f8f1cb; --primary:#e6bf2a; --on-primary:#2b2300;
}
[data-theme="mint"] {
  --bg:#f0f9f8; --card:#ffffff; --text:#12302f; --sub:#568280; --line:#d3ebe9;
  --soft:#dcf3f1; --primary:#16938e; --on-primary:#ffffff;
}
[data-theme="berry"] {
  --bg:#fcf2f5; --card:#ffffff; --text:#3a1420; --sub:#85505d; --line:#f0d9e0;
  --soft:#f9e1e8; --primary:#c2395b; --on-primary:#ffffff;
}
[data-theme="coffee"] {
  --bg:#f7f2ee; --card:#ffffff; --text:#2e1f16; --sub:#7b6455; --line:#e8dcd2;
  --soft:#efe4db; --primary:#8a5a3c; --on-primary:#ffffff;
}
[data-theme="graphite"] {
  --bg:#15181a; --card:#1f2427; --text:#e8eceb; --sub:#9aa6a3; --line:#2f3739;
  --soft:#263033; --primary:#6fcf97; --on-primary:#0d2418;
}

/* 狀態顏色（所有配色共用） */
:root {
  --ok:#2e9d5b; --warn:#e08a00; --bad:#d64545; --expired:#7b1f1f;
  --tabbar-h:60px;
}

/* ===== 基本 ===== */
* { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body {
  margin:0; padding:0; max-width:100%; overflow-x:hidden;
  overscroll-behavior-x:none; touch-action:pan-y pinch-zoom;
}
body {
  font-family:var(--font, -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", sans-serif);
  background:var(--bg); color:var(--text); font-size:15px; line-height:1.45;
  -webkit-text-size-adjust:100%;
}
[hidden] { display:none !important; }
h1 { font-size:26px; margin:6px 0; }
h2 { font-size:16px; margin:0 0 6px; }
p { margin:4px 0; }
.muted { color:var(--sub); }
.small { font-size:13px; }
.error { color:var(--bad); font-size:14px; max-width:320px; word-break:break-word; }

/* 輸入框字體至少 16px，避免 iPhone 自動放大 */
input, select, textarea, button { font-family:inherit; font-size:16px; }
input, select, textarea {
  width:100%; max-width:100%; padding:9px 10px; border:1px solid var(--line);
  border-radius:10px; background:var(--card); color:var(--text);
}

/* ===== 全螢幕狀態頁 ===== */
.screen { min-height:100vh; min-height:100dvh; padding:24px; }
.center { display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; gap:6px; }
.logo { font-size:64px; line-height:1; }

/* ===== 按鈕 ===== */
.btn {
  border:1px solid var(--line); background:var(--card); color:var(--text);
  padding:10px 16px; border-radius:12px; font-weight:600; cursor:pointer;
}
.btn.primary { background:var(--primary); color:var(--on-primary); border-color:var(--primary); }
.btn.big { padding:13px 22px; margin-top:14px; min-width:220px; }
.btn:active { opacity:.8; }

/* ===== 主畫面 ===== */
.topbar {
  position:sticky; top:0; z-index:10; display:flex; align-items:center; justify-content:space-between;
  padding:calc(env(safe-area-inset-top) + 10px) 16px 6px; background:var(--bg); color:var(--text);
}
.topbar-title { font-weight:800; font-size:24px; letter-spacing:.5px; }
.topbar-right { display:flex; align-items:center; gap:8px; }
#btn-font { font-size:15px; font-weight:700; color:var(--text); }
.gear-btn {
  width:38px; height:38px; border-radius:50%; border:1px solid var(--line); background:var(--card);
  font-size:18px; padding:0; cursor:pointer; display:flex; align-items:center; justify-content:center;
}
.gear-btn.active { background:var(--primary); border-color:var(--primary); }
.avatar { width:34px; height:34px; border-radius:50%; border:2px solid var(--card); object-fit:cover; box-shadow:0 1px 4px rgba(0,0,0,.15); }

.main { padding:6px 12px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 40px); }
.card {
  background:var(--card); border:1px solid var(--line); border-radius:16px;
  padding:12px 14px; margin-bottom:10px; box-shadow:0 1px 3px rgba(0,0,0,.04);
}

/* 底部浮動導覽列：食材 ｜ ＋ ｜ 價格 */
.tabbar {
  position:fixed; left:14px; right:14px; z-index:10; display:grid; grid-template-columns:1fr 84px 1fr;
  bottom:calc(env(safe-area-inset-bottom) + 10px); height:var(--tabbar-h);
  background:var(--card); border:1px solid var(--line); border-radius:28px;
  box-shadow:0 6px 20px rgba(0,0,0,.12);
}
.tabbar .tab {
  border:0; background:transparent; color:var(--sub);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  font-size:12px; gap:1px; cursor:pointer;
}
.tab-ico { font-size:20px; line-height:1; }
.tabbar .tab.active { color:var(--primary); font-weight:700; }

/* ===== 食材清單 ===== */
.action-row { display:grid; grid-template-columns:1fr 1fr 1.3fr; gap:8px; margin:4px 0 10px; }
.pill {
  border:1px solid var(--line); background:var(--card); color:var(--text); border-radius:999px;
  padding:9px 6px; font-size:14px; font-weight:600; cursor:pointer; white-space:nowrap;
  box-shadow:0 1px 3px rgba(0,0,0,.04);
}
.pill:active { background:var(--soft); }

.soon {
  display:flex; flex-wrap:wrap; align-items:center; gap:6px 8px; padding:10px 12px; margin-bottom:10px;
  background:var(--card); border:1px solid var(--line); border-radius:16px;
}
.soon-label { color:var(--primary); font-weight:700; font-size:13px; margin-right:2px; }
.soon-item { display:inline-flex; align-items:center; gap:5px; border:0; background:transparent; color:var(--text); font-size:14px; padding:2px 0; cursor:pointer; }
.soon-tag { font-size:12px; font-weight:700; padding:2px 8px; border-radius:999px; color:#fff; background:var(--warn); }
.soon-tag.bad { background:var(--bad); }
.soon-tag.expired { background:var(--expired); }

.filters { display:flex; flex-direction:column; gap:10px; margin-bottom:10px; }
.seg {
  display:grid; grid-auto-flow:column; grid-auto-columns:1fr; gap:4px; padding:4px;
  background:var(--card); border:1px solid var(--line); border-radius:16px;
}
.seg-btn {
  border:0; background:transparent; color:var(--text); border-radius:12px; padding:8px 2px;
  font-size:14px; cursor:pointer; display:flex; align-items:center; justify-content:center; gap:4px; white-space:nowrap;
}
.seg-btn.on { background:var(--primary); color:var(--on-primary); font-weight:700; }
.seg-n { font-size:12px; opacity:.7; }

.cat-grid { display:grid; grid-template-columns:repeat(9, 1fr); gap:2px; }
.cat { border:0; background:transparent; color:var(--sub); display:flex; flex-direction:column; align-items:center; gap:3px; padding:0; cursor:pointer; min-width:0; }
.cat-ico {
  width:36px; height:36px; border-radius:12px; background:var(--card); border:1px solid var(--line);
  display:flex; align-items:center; justify-content:center; font-size:18px; line-height:1;
}
.cat-lbl { font-size:11px; white-space:nowrap; }
.cat.on .cat-ico { background:var(--primary); border-color:var(--primary); color:var(--on-primary); }
.cat.on .cat-lbl { color:var(--primary); font-weight:700; }

.chips { display:flex; flex-wrap:wrap; gap:6px; }
.chip {
  border:1px solid var(--line); background:var(--card); color:var(--text);
  padding:5px 11px; border-radius:999px; font-size:14px; cursor:pointer; line-height:1.3;
}
.chip.on { background:var(--primary); color:var(--on-primary); border-color:var(--primary); font-weight:600; }
.chip.removable { background:var(--soft); }

.items-list { display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.row {
  display:flex; flex-direction:column; justify-content:space-between; gap:6px; min-width:0; min-height:70px;
  background:var(--card); border:1px solid var(--line); border-radius:16px; padding:10px 10px 9px;
  cursor:pointer; box-shadow:0 1px 3px rgba(0,0,0,.04);
}
.row:active { background:var(--soft); }
.row-top { display:flex; align-items:flex-start; gap:8px; min-width:0; }
.row-name { font-weight:600; font-size:15px; line-height:1.3; overflow-wrap:anywhere; padding-top:2px; }
.row-bot { display:flex; align-items:center; justify-content:space-between; gap:6px; font-size:12px; color:var(--sub); min-height:20px; }
.qty { overflow-wrap:anywhere; }
.exp { text-align:right; margin-left:auto; }
.exp.warn { color:var(--warn); font-weight:600; }
.exp.bad { color:var(--bad); font-weight:600; }
.exp-pill { margin-left:auto; font-size:12px; font-weight:700; color:#fff; padding:2px 9px; border-radius:999px; background:var(--bad); white-space:nowrap; }
.exp-pill.expired { background:var(--expired); }

.check {
  flex:none; width:24px; height:24px; border-radius:50%; border:2px solid var(--line);
  background:transparent; color:transparent; font-size:13px; line-height:1; cursor:pointer;
  display:flex; align-items:center; justify-content:center; padding:0;
}
.check:active { background:var(--primary); color:var(--on-primary); border-color:var(--primary); }

.empty { text-align:center; color:var(--sub); padding:28px 12px; }
.used-card { margin-top:12px; }
.used-card summary { cursor:pointer; font-weight:600; }
.used-row { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 0; border-top:1px solid var(--line); margin-top:6px; }
.used-name { overflow-wrap:anywhere; color:var(--sub); text-decoration:line-through; }

.mini {
  border:1px solid var(--line); background:var(--card); color:var(--text);
  padding:7px 11px; border-radius:9px; font-size:14px; cursor:pointer; white-space:nowrap;
}

/* 中間的新增鈕（浮在導覽列上） */
.fab {
  position:fixed; left:50%; transform:translateX(-50%); z-index:11;
  bottom:calc(env(safe-area-inset-bottom) + 10px + var(--tabbar-h) - 34px);
  width:62px; height:62px; border-radius:50%; border:4px solid var(--bg); font-size:32px; line-height:1;
  background:var(--primary); color:var(--on-primary);
  box-shadow:0 6px 16px rgba(0,0,0,.25); cursor:pointer; padding:0;
}
.fab:active { transform:translateX(-50%) scale(.95); }

/* ===== 新增 / 編輯表單 ===== */
body.modal-open { overflow:hidden; }
.sheet-wrap { position:fixed; inset:0; z-index:30; display:flex; flex-direction:column; justify-content:flex-end; overscroll-behavior:none; }
.sheet-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.45); touch-action:none; }
.sheet {
  position:relative; background:var(--bg); border-radius:18px 18px 0 0;
  height:94vh; height:94dvh; display:flex; flex-direction:column; overflow:hidden;
}
.sheet.snap { transition:transform .2s ease; }
.sheet-head { touch-action:none; }
.text-btn { border:0; background:transparent; color:var(--sub); font-size:16px; padding:8px 4px; cursor:pointer; }
.sheet-head { display:flex; align-items:center; justify-content:space-between; padding:2px 16px 8px; flex:none; }
.sheet-head h2 { margin:0; font-size:18px; }
.sheet-body { flex:1 1 auto; min-height:0; overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y; padding:0 14px 12px; }
.sheet-foot {
  display:flex; gap:10px; padding:10px 14px calc(env(safe-area-inset-bottom) + 10px);
  border-top:1px solid var(--line); background:var(--bg);
}
.sheet-foot .grow { flex:1; }
.label { font-size:13px; font-weight:600; color:var(--sub); margin:12px 0 5px; display:block; }
.two { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.date-row { display:grid; grid-template-columns:1fr auto; gap:8px; align-items:center; }
.date-row input[type="date"] { min-height:42px; }
.btn.danger { color:var(--bad); border-color:var(--bad); }

/* ===== 價格紀錄 ===== */
.price-search { margin-bottom:10px; border-radius:14px; }
.p-rows { background:var(--card); border:1px solid var(--line); border-radius:16px; overflow:hidden; }
.p-row {
  width:100%; display:flex; align-items:center; justify-content:space-between; gap:10px; text-align:left;
  border:0; border-top:1px solid var(--line); background:transparent; color:var(--text); padding:11px 14px; cursor:pointer;
}
.p-row:first-child { border-top:0; }
.p-row:active { background:var(--soft); }
.p-left { min-width:0; }
.p-name { font-weight:600; font-size:16px; overflow-wrap:anywhere; }
.p-sub { font-size:12px; color:var(--sub); margin-top:2px; }
.p-avg { flex:none; font-size:17px; font-weight:600; }
.p-avg-l { font-size:12px; color:var(--sub); margin-right:3px; font-weight:400; }
.p-tiles { display:grid; grid-template-columns:1.3fr 1fr 1fr; gap:8px; margin-top:4px; }
.p-tile { background:var(--card); border:1px solid var(--line); border-radius:14px; padding:12px 6px; text-align:center; }
.p-tile.main { background:var(--soft); border-color:var(--primary); }
.p-tile-v { font-size:20px; font-weight:600; }
.p-tile-l { font-size:12px; color:var(--sub); margin-top:2px; }
.p-title { font-size:13px; font-weight:600; color:var(--sub); margin:14px 2px 6px; }
.p-list { background:var(--card); border:1px solid var(--line); border-radius:14px; overflow:hidden; }
.p-line { display:flex; align-items:center; gap:8px; padding:10px 12px; border-top:1px solid var(--line); }
.p-line:first-child { border-top:0; }
.p-line-name { overflow-wrap:anywhere; }
.p-line-v { margin-left:auto; font-weight:600; }
.p-date { min-width:84px; }
.p-best { background:var(--bad); color:#fff; font-size:11px; font-weight:700; padding:1px 8px; border-radius:999px; }

/* ===== 換字體 ===== */
.font-list { display:flex; flex-direction:column; gap:8px; margin:4px 0 10px; }
.font-opt { text-align:left; border:1px solid var(--line); background:var(--card); color:var(--text); border-radius:14px; padding:11px 14px; cursor:pointer; }
.font-opt.on { border:2px solid var(--primary); padding:10px 13px; background:var(--soft); }
.font-name { font-size:18px; }
.font-desc { font-size:12px; color:var(--sub); margin-top:2px; }

/* ===== 貼上清單 / 確認頁 ===== */
.sheet-step { display:flex; flex-direction:column; min-height:0; flex:1; }
textarea { min-height:150px; resize:vertical; line-height:1.5; }
input[type="checkbox"] { width:24px; height:24px; padding:0; accent-color:var(--primary); }
.rv-list { margin-top:12px; }
.rv-row { background:var(--card); border:1px solid var(--line); border-radius:12px; padding:8px; margin-bottom:8px; display:grid; gap:6px; }
.rv-row.off { opacity:.45; }
.rv-top { display:grid; grid-template-columns:auto 1fr; gap:10px; align-items:center; }
.rv-name { font-weight:700; }
.rv-grid3 { display:grid; grid-template-columns:1fr 1fr 1fr; gap:6px; }
.rv-grid2 { display:grid; grid-template-columns:1fr 1.4fr; gap:6px; }
.rv-row select { padding:8px 4px; min-width:0; }
.btn:disabled { opacity:.5; }

.offscreen { position:fixed; left:-9999px; top:0; opacity:0; }

/* ===== 底部提示 ===== */
.toast {
  position:fixed; left:12px; right:12px; z-index:50;
  bottom:calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px);
  background:#222; color:#fff; border-radius:12px; padding:11px 14px;
  display:flex; align-items:center; justify-content:space-between; gap:10px; font-size:15px;
  box-shadow:0 4px 16px rgba(0,0,0,.3);
}
.toast button { border:0; background:transparent; color:#8ee0b0; font-weight:700; font-size:15px; padding:2px 6px; cursor:pointer; }

/* ===== 配色選擇 ===== */
.theme-grid { display:grid; grid-template-columns:repeat(5, 1fr); gap:8px; margin-top:8px; }
.theme-btn {
  border:2px solid transparent; background:transparent; padding:4px 0; border-radius:12px;
  display:flex; flex-direction:column; align-items:center; gap:4px; color:var(--text);
  font-size:11px; cursor:pointer;
}
.theme-dot { width:34px; height:34px; border-radius:50%; border:1px solid var(--line); }
.theme-btn.selected { border-color:var(--primary); background:var(--soft); }

/* 照片辨識中 */
.busy { position:fixed; inset:0; z-index:60; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; }
.busy[hidden] { display:none; }
.busy-box { background:var(--card, #fff); color:inherit; padding:20px 26px; border-radius:14px; display:flex; flex-direction:column; align-items:center; gap:12px; font-size:16px; }
.spinner { width:30px; height:30px; border:4px solid rgba(128,128,128,.3); border-top-color:var(--primary, #3f8f5f); border-radius:50%; animation:spin .8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ===== 新增 / 編輯表單（新版面） ===== */
.grabber { height:30px; display:flex; justify-content:center; align-items:flex-start; padding-top:10px; cursor:pointer; touch-action:none; flex:none; }
.grabber::before { content:""; width:44px; height:5px; border-radius:3px; background:var(--sub); opacity:.45; }
.sheet { border-radius:24px 24px 0 0; }
.opt-grid { display:grid; grid-template-columns:repeat(4, 1fr); gap:6px; }
.opt-btn {
  border:1px solid var(--line); background:var(--card); color:var(--text); border-radius:12px;
  padding:9px 2px; font-size:14px; cursor:pointer; white-space:nowrap;
}
.opt-btn.on { background:var(--primary); color:var(--on-primary); border-color:var(--primary); font-weight:700; }
.label-row { display:flex; align-items:baseline; justify-content:space-between; }
.label .opt { font-weight:400; opacity:.7; }
.link { border:0; background:transparent; color:var(--primary); font-size:13px; padding:12px 0 5px; cursor:pointer; }
.two > div { min-width:0; }
.date-field { min-height:44px; text-align:left; cursor:pointer; }

/* ===== 自製日曆（星期一開頭） ===== */
.cal-wrap { position:fixed; inset:0; z-index:70; display:flex; align-items:center; justify-content:center; padding:20px; }
.cal-backdrop { position:absolute; inset:0; background:rgba(0,0,0,.45); touch-action:none; }
.cal { position:relative; width:100%; max-width:340px; background:var(--card); color:var(--text); border-radius:22px; padding:14px 12px 10px; box-shadow:0 10px 30px rgba(0,0,0,.3); }
.cal-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:8px; }
.cal-title { font-weight:700; font-size:17px; }
.cal-nav { width:40px; height:40px; border-radius:50%; border:0; background:var(--soft); color:var(--text); font-size:22px; line-height:1; cursor:pointer; padding:0; }
.cal-grid { display:grid; grid-template-columns:repeat(7, 1fr); gap:2px; text-align:center; }
.cal-wd { font-size:13px; color:var(--sub); padding:4px 0; }
.cal-day { height:40px; border:0; background:transparent; color:var(--text); font-size:16px; border-radius:50%; cursor:pointer; padding:0; }
.cal-day.today { border:1.5px solid var(--primary); }
.cal-day.on { background:var(--primary); color:var(--on-primary); font-weight:700; }
.cal-foot { display:flex; justify-content:center; margin-top:6px; }
.cal-today { border:0; background:transparent; color:var(--primary); font-weight:700; font-size:16px; padding:8px 18px; cursor:pointer; }
.sheet-foot .btn { border-radius:999px; }
