/* Kelly的冰箱 — iPhone 風格配色 */
:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --text: #1C1C1E;
  --muted: #8E8E93;
  --line: #E5E5EA;
  --fill: #E9E9EB;
  --blue: #007AFF;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --red: #FF3B30;
  --green: #34C759;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.35;
  overflow-x: hidden;                 /* 禁止左右滑動 */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

button { font-family: inherit; color: inherit; }

.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 90px);
}

h1 { font-size: 22px; margin: 0 0 6px; font-weight: 700; }
p  { margin: 4px 0; }
.muted { color: var(--muted); }
.error-text { color: var(--red); font-size: 14px; min-height: 1em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 2px 0; min-height: 0; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; }

.center-view {
  min-height: 80vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
}
.center-view .card { width: 100%; max-width: 360px; padding: 28px 20px; }
.app-icon { font-size: 48px; margin-bottom: 8px; }

/* 頂部 */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px 0; }
.topbar h1 { margin: 0; font-size: 28px; }
.summary { color: var(--muted); font-size: 13px; margin: 0 2px 8px; }

/* 按鈕 */
.btn {
  appearance: none; border: none; border-radius: 10px;
  padding: 12px 16px; font-size: 17px; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.5; }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-secondary { background: var(--fill); color: var(--blue); }
.btn-danger { background: var(--fill); color: var(--red); }
.btn-text {
  appearance: none; background: none; border: none;
  color: var(--blue); font-size: 17px; padding: 8px; cursor: pointer;
}
.btn-text.strong { font-weight: 600; }
.btn-small {
  appearance: none; border: none; border-radius: 8px;
  background: var(--fill); color: var(--blue);
  font-size: 15px; padding: 6px 12px; flex-shrink: 0;
}

/* 功能按鈕列（會自動平均分配寬度，不會左右滑） */
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.action-btn {
  appearance: none; border: none; background: var(--card); border-radius: 10px;
  padding: 8px 4px; font-size: 13px; color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
}
.action-btn span { font-size: 20px; }
.action-btn:active { background: var(--fill); }

/* 價格紀錄 */
.price-card { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.price-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.price-name { font-size: 16px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price-avg { font-size: 16px; font-weight: 600; color: var(--blue); flex-shrink: 0; }
.price-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.store-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 5px 0 0; border-top: 0.5px solid var(--line); margin-top: 6px; }
.store-row .cheap { color: var(--green); font-weight: 600; }
.history { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.textarea { min-height: 260px; resize: vertical; line-height: 1.5; }

/* 分段按鈕（存放位置） */
.segmented {
  display: flex; gap: 2px;
  background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 8px;
}
.seg {
  flex: 1 1 0; min-width: 0;
  appearance: none; border: none; background: transparent;
  border-radius: 7px; padding: 7px 2px; font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seg.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.12); font-weight: 600; }

/* 小標籤（種類、店家） — 會自動換行，不會左右滑 */
.chips, .quick-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  appearance: none; border: none; background: var(--card);
  border-radius: 16px; padding: 5px 11px; font-size: 14px;
}
.sheet .chip { background: var(--fill); }
.chip.active { background: var(--blue) !important; color: #fff; }

/* 品名下方的常買建議 */
.suggest { align-items: center; margin-top: 2px; }
.suggest-label { font-size: 13px; color: var(--muted); }
.sheet .suggest .chip { background: #DCEBFF; color: var(--blue); }

/* 清單 */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.item-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-bottom: 0.5px solid var(--line);
}
.item-row:last-child { border-bottom: none; }
.check {
  flex-shrink: 0; width: 24px; height: 24px; padding: 0;
  border-radius: 50%; border: 2px solid #C7C7CC; background: none; cursor: pointer;
}
.check:active { background: var(--green); border-color: var(--green); }
.item-main { flex: 1 1 auto; min-width: 0; cursor: pointer; }
.item-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; margin: 0; }

.badge {
  flex-shrink: 0; font-size: 12px; font-weight: 600;
  padding: 3px 8px; border-radius: 10px; white-space: nowrap;
}
.badge-red    { background: var(--red); color: #fff; }
.badge-orange { background: var(--orange); color: #fff; }
.badge-yellow { background: #FFF4CC; color: #8A6D00; }
.badge-green  { background: #E3F7E8; color: #1E7B34; }
.badge-gray   { background: var(--fill); color: var(--muted); }

.recent-link { display: block; margin: 12px auto 0; font-size: 14px; }

/* 右下角 ＋ */
.fab {
  position: fixed; right: 20px; bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--blue); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 12px rgba(0,122,255,0.35); cursor: pointer; z-index: 10;
}

/* 底部面板 */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,0.3);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  width: 100%; max-width: 640px; max-height: 94vh;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 14px 14px 0 0;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); padding: 8px 0; margin-bottom: 4px;
  border-bottom: 0.5px solid var(--line);
}
.sheet-head strong { font-size: 17px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 12px 2px 6px; }

/* 輸入框：至少 16px，避免 iPhone 自動放大 */
input, select, textarea { font-size: 16px; font-family: inherit; }
.input {
  display: block; width: 100%; max-width: 100%;
  border: none; border-radius: 10px; background: var(--card);
  padding: 11px 12px; color: var(--text); margin-bottom: 6px;
  -webkit-appearance: none; appearance: none; min-height: 44px;
}
input[type="date"].input { text-align: left; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }

/* 底部提示 */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  width: calc(100% - 32px); max-width: 480px; z-index: 30;
  background: rgba(30,30,30,0.92); color: #fff;
  border-radius: 12px; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 15px;
}
.toast-action {
  appearance: none; border: none; background: none;
  color: #64D2FF; font-size: 15px; font-weight: 600; flex-shrink: 0; cursor: pointer;
}

.spinner {
  width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--blue);
  border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
