/* 鮮知道 — 手機優先、只能上下捲動 */
:root {
  --primary: #0F766E;
  --primary-dark: #115E59;
  --primary-soft: #CCFBF1;
  --bg: #F6F8F8;
  --card: #FFFFFF;
  --text: #1F2937;
  --muted: #6B7280;
  --line: #E5E7EB;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --warn: #B45309;
  --warn-soft: #FEF3C7;
  --soon: #92400E;
  --soon-soft: #FFFBEB;
  --ok: #4B5563;
  --ok-soft: #F3F4F6;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 24px; margin: 8px 0; }
h2 { font-size: 18px; margin: 0; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error-text { color: var(--danger); font-size: 14px; max-width: 320px; }

/* 輸入框至少 16px，避免 iPhone 自動放大 */
input, select, textarea, button { font: inherit; }
input, select, textarea {
  font-size: 16px;
  width: 100%;
  max-width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
input[type="date"] { min-height: 42px; -webkit-appearance: none; appearance: none; }
textarea { resize: vertical; }

/* 按鈕 */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  background: var(--ok-soft);
  color: var(--text);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn-lg { min-height: 50px; font-size: 17px; width: 100%; max-width: 340px; }
.btn-grow { flex: 1; }
.btn:disabled { opacity: .5; }
.btn-x { border: 0; background: transparent; font-size: 20px; width: 44px; height: 44px; cursor: pointer; color: var(--muted); }

/* 置中畫面 */
.center-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
}
.logo-big {
  width: 72px; height: 72px; border-radius: 20px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 38px; font-weight: 700;
}
.logo-big.denied { background: var(--danger); }
.login-icon { width: 88px; height: 88px; border-radius: 22px; }

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  background: rgba(246, 248, 248, .96);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--primary-dark); }
.brand img { border-radius: 7px; }
.topbar-actions { display: flex; gap: 6px; }

main { padding: 8px 10px calc(84px + var(--safe-bottom)); max-width: 720px; margin: 0 auto; }

/* 篩選 */
.filters { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 14px;
  min-height: 32px;
  cursor: pointer;
  color: var(--text);
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .count { opacity: .7; margin-left: 2px; font-size: 12px; }

.summary { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin: 4px 2px 6px; }
.summary b.exp { color: var(--danger); }
.summary b.soon { color: var(--warn); }

/* 食材清單：緊湊 */
.item-list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px 7px 4px;
  border-bottom: 1px solid var(--line);
  min-height: 48px;
}
.item:last-child { border-bottom: 0; }
.item.expired { background: #FFF7F7; }
.done-btn {
  flex: none;
  width: 40px; height: 40px;
  border: 0; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.done-btn::before {
  content: "";
  width: 20px; height: 20px;
  border: 2px solid #9CA3AF; border-radius: 50%;
}
.done-btn:active::before { background: var(--primary-soft); border-color: var(--primary); }
.item-main { flex: 1; min-width: 0; cursor: pointer; }
.item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-name .qty { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 4px; }
.item-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  flex: none;
  font-size: 12px; font-weight: 700;
  border-radius: 8px;
  padding: 3px 7px;
  min-width: 58px; text-align: center;
  background: var(--ok-soft); color: var(--ok);
}
.badge.expired { background: var(--danger); color: #fff; }
.badge.today { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.soon { background: var(--soon-soft); color: var(--soon); border: 1px solid var(--warn-soft); }
.badge.none { background: transparent; color: #9CA3AF; font-weight: 400; }

.group-title { list-style: none; padding: 6px 10px; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); }

.empty { text-align: center; padding: 40px 10px; }

/* 價格 */
.price-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.price-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.price-card h3 { margin: 0 0 4px; font-size: 15px; }
.price-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.price-stats b { font-size: 15px; }
.price-stores { margin-top: 6px; font-size: 13px; color: var(--muted); }
.price-stores .cheap { color: var(--primary-dark); font-weight: 700; }

/* 底部導覽 */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.nav-btn {
  flex: 1;
  border: 0; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 6px 0; min-height: 56px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.nav-btn span { font-size: 20px; line-height: 1.1; }
.nav-btn.active { color: var(--primary); font-weight: 700; }
.nav-add span {
  background: var(--primary); color: #fff;
  width: 36px; height: 36px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.nav-add { color: var(--primary); font-weight: 700; }

/* 底部抽屜 */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .35); }
.sheet-panel {
  position: relative;
  width: 100%; max-width: 640px;
  max-height: 94vh; max-height: 94dvh;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(12px + var(--safe-bottom));
}
.sheet-short { max-height: 70vh; }
.sheet-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.form { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.hint { color: var(--primary-dark); font-size: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 15px; }
.seg button.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.quick-dates { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: -4px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0 4px; }

.add-options { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; }
.add-option {
  display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto;
  align-items: center; text-align: left;
  border: 1px solid var(--line); background: #fff; border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; min-height: 60px; color: var(--text);
}
.add-option span { grid-row: 1 / 3; font-size: 26px; }
.add-option b { font-size: 16px; }
.add-option small { color: var(--muted); font-size: 13px; }

.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 10px; margin: 0; }

/* 確認清單 */
.confirm-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.c-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.c-item.off { opacity: .55; }
.c-top { display: flex; align-items: center; gap: 8px; }
.c-top input[type="checkbox"] { width: 22px; height: 22px; flex: none; accent-color: var(--primary); }
.c-top input[type="text"] { flex: 1; }
.c-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.c-grid select, .c-grid input { padding: 7px 8px; }
.c-tag { font-size: 12px; color: var(--warn); }

/* 處理中 */
.busy { position: fixed; inset: 0; z-index: 80; background: rgba(255, 255, 255, .7); display: flex; align-items: center; justify-content: center; }
.busy-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; text-align: center; max-width: 80vw; }
.spinner { width: 32px; height: 32px; margin: 0 auto 8px; border: 3px solid var(--primary-soft); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.dialog-box { position: relative; margin: auto 16px; align-self: center; background: #fff; border-radius: 14px; padding: 16px; width: 100%; max-width: 360px; }

/* 提示列 */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 90;
  bottom: calc(68px + var(--safe-bottom));
  margin: 0 auto; max-width: 520px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #111827; color: #fff;
  padding: 10px 12px; border-radius: 12px;
  font-size: 14px;
}
.toast-btn { border: 0; background: transparent; color: #5EEAD4; font-weight: 700; font-size: 15px; min-height: 36px; padding: 0 6px; cursor: pointer; }

@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 18px; }
}
