:root,
[data-theme="light"] {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-soft: #f0eee8;
  --border: #e6e3da;
  --text: #181a1f;
  --muted: #6c727f;
  --primary: #15803d;
  --primary-bright: #16a34a;
  --primary-soft: rgba(22, 163, 74, 0.11);
  --accent: #ea580c;
  --accent-soft: rgba(234, 88, 12, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --protein: #2563eb;
  --carbs: #d97706;
  --fat: #db2777;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.055);
  --shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.04);
  --glass: rgba(246, 245, 241, 0.84);
  --tab-glass: rgba(255, 255, 255, 0.9);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171c24;
  --surface-soft: #212834;
  --border: #2a3241;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --primary: #22c55e;
  --primary-bright: #16a34a;
  --primary-soft: rgba(34, 197, 94, 0.15);
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --protein: #60a5fa;
  --carbs: #fbbf24;
  --fat: #f472b6;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --glass: rgba(14, 17, 22, 0.84);
  --tab-glass: rgba(23, 28, 36, 0.92);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.83rem; }
.mb-8 { margin-bottom: 8px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-14 { margin-bottom: 14px; }
.mb-16 { margin-bottom: 16px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-16 { margin-top: 16px; }
.full { width: 100%; }

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-mark { display: inline-flex; margin-bottom: 14px; }
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; letter-spacing: -0.02em; }
.auth-card .field { text-align: left; }

/* App Shell */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 18px 10px;
  background: var(--glass);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.topbar-kicker { font-size: 0.75rem; font-weight: 600; color: var(--muted); letter-spacing: 0.01em; }
.topbar-title { margin: 0; font-size: 1.48rem; font-weight: 800; letter-spacing: -0.03em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease;
}
.circle-btn:active { transform: scale(0.93); }

.content {
  flex: 1;
  padding: 6px 16px calc(100px + var(--safe-bottom));
}

.tab-panel { display: none; animation: fadeIn 0.18s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* Floating Bottom Tab Bar */
.tabbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  max-width: 656px;
  margin: 0 auto;
  padding: 7px 6px;
  background: var(--tab-glass);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 6px 2px;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.18s ease;
}
.tab-btn.active {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Layouts & Cards */
.stack { display: flex; flex-direction: column; gap: 11px; }
.stack-tight { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.section-kicker {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
  margin-bottom: 2px;
}
.section-title { margin: 0; font-size: 1.06rem; font-weight: 800; letter-spacing: -0.02em; }
.card-heading { margin: 0; font-size: 1.02rem; font-weight: 700; letter-spacing: -0.015em; }

/* Week Strip & Day Pills */
.week-strip-wrap { margin-bottom: 14px; }
.week-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.week-range-text { font-size: 0.88rem; font-weight: 700; color: var(--muted); }
.pill-arrow {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}
.day-pills-bar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  transition: all 0.16s ease;
  box-shadow: var(--shadow-sm);
}
.day-pill .dp-w { display: block; font-size: 0.68rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.day-pill .dp-d { display: block; font-size: 1rem; font-weight: 800; margin-top: 2px; }
.day-pill .dp-dot { display: block; width: 5px; height: 5px; border-radius: 50%; margin: 4px auto 0; background: transparent; }
.day-pill.has-meals .dp-dot { background: var(--primary); }
.day-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  transform: translateY(-2px);
}
.day-pill.active .dp-w { color: rgba(255, 255, 255, 0.8); }
.day-pill.active .dp-dot { background: #fff; }

/* Nutrition Ring Dashboard */
.nutrition-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
  padding: 18px 16px;
}
.ring-wrap {
  position: relative;
  width: 98px;
  height: 98px;
  flex-shrink: 0;
}
.ring-wrap svg { transform: rotate(-90deg); width: 98px; height: 98px; }
.ring-bg { fill: none; stroke: var(--surface-soft); stroke-width: 9; }
.ring-fg { fill: none; stroke: var(--primary-bright); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.ring-kcal { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.ring-sub { font-size: 0.66rem; color: var(--muted); font-weight: 600; }

.macro-grid { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.macro-row-top { display: flex; justify-content: space-between; font-size: 0.78rem; font-weight: 700; margin-bottom: 3px; }
.macro-track { height: 6px; border-radius: 99px; background: var(--surface-soft); overflow: hidden; }
.macro-fill { height: 100%; border-radius: 99px; transition: width 0.35s ease; }
.fill-p { background: var(--protein); }
.fill-c { background: var(--carbs); }
.fill-f { background: var(--fat); }

/* Craving / Mood Picker */
.craving-card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
}
.craving-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}
.crave-chip {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.crave-chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.25);
}
.craving-input-row { display: flex; gap: 8px; align-items: center; }

/* Meal & Recipe Cards */
.meal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.meal-card.cooked { opacity: 0.6; }
.meal-accent-bar { height: 5px; width: 100%; }
.accent-breakfast { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.accent-lunch { background: linear-gradient(90deg, #16a34a, #10b981); }
.accent-dinner { background: linear-gradient(90deg, #ea580c, #f97316); }
.accent-snack { background: linear-gradient(90deg, #8b5cf6, #ec4899); }

.meal-card-body { padding: 14px 16px; }
.meal-top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.slot-pill {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.meal-title-btn {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  cursor: pointer;
}
.meal-desc { font-size: 0.83rem; color: var(--muted); margin: 0 0 10px; }

.stat-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.stat-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
}
.stat-pill.kcal { background: var(--primary-soft); color: var(--primary); }
.stat-pill.price { background: var(--accent-soft); color: var(--accent); }

.meal-footer {
  display: flex;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Shopping Banner & Items */
.spend-banner {
  background: linear-gradient(135deg, rgba(22, 163, 74, 0.09), rgba(234, 88, 12, 0.06));
  margin-bottom: 12px;
}
.big-price { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; color: var(--primary); }
.store-pills-row { display: flex; gap: 7px; overflow-x: auto; margin-top: 12px; padding-bottom: 2px; }
.store-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.78rem;
  font-weight: 700;
}

.quick-add-bar {
  display: flex;
  gap: 7px;
  padding: 10px;
  margin-bottom: 14px;
  align-items: center;
}
.quick-add-bar input[type="text"] { flex: 1; }
.input-mini { width: 64px !important; padding: 10px 6px !important; text-align: center; }

.shop-store-group { margin-bottom: 10px; }
.shop-store-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 8px;
  font-weight: 800;
  font-size: 0.9rem;
}
.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 7px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: opacity 0.16s ease;
}
.shop-item.checked { opacity: 0.45; }
.shop-item.checked .shop-name { text-decoration: line-through; }
.shop-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
}
.shop-item.checked .shop-circle { background: var(--primary); }
.shop-main { flex: 1; min-width: 0; }
.shop-name { font-weight: 700; font-size: 0.94rem; }
.shop-meta { font-size: 0.77rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; margin-top: 1px; }
.shop-price { font-weight: 800; font-size: 0.92rem; color: var(--primary); white-space: nowrap; }

/* Receipt Scanner Hero */
.scanner-hero {
  background: linear-gradient(135deg, #15803d 0%, #0f766e 60%, #0369a1 100%);
  border: none;
  color: #fff;
  padding: 20px;
}
.scanner-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.scanner-title { margin: 0 0 6px; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.scanner-desc { margin: 0 0 14px; font-size: 0.86rem; color: rgba(255, 255, 255, 0.88); }

.stat-card { padding: 14px 16px; }
.stat-label { font-size: 0.76rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.stat-val { font-size: 1.38rem; font-weight: 800; letter-spacing: -0.025em; }

/* Buttons & Form Inputs */
.btn {
  border: none;
  border-radius: 14px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: transform 0.12s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: var(--surface-soft); color: var(--text); border: 1px solid var(--border); }
.btn-white { background: #fff; color: #14532d; }
.btn-glass { background: rgba(255, 255, 255, 0.16); color: #fff; border: 1px solid rgba(255, 255, 255, 0.28); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 8px 13px; font-size: 0.84rem; border-radius: 12px; }
.btn-xs { padding: 6px 10px; font-size: 0.78rem; border-radius: 10px; }
.btn-icon { width: 42px; height: 42px; padding: 0; font-size: 1.25rem; flex-shrink: 0; }

.field { margin-bottom: 11px; }
.field label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.94rem;
  font-family: inherit;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); background: var(--surface); }
textarea { min-height: 70px; resize: vertical; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 10px 0;
  cursor: pointer;
}
.switch-row input { width: 18px; height: 18px; accent-color: var(--primary); }

/* Segmented Control */
.segmented {
  display: inline-flex;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 3px;
}
.segmented-full { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.seg-btn {
  border: none;
  background: none;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Badges & Avatars */
.store-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--surface-soft);
  color: var(--text);
}
.pill-badge.ok { background: var(--primary-soft); color: var(--primary); }
.pill-badge.deal { background: var(--accent-soft); color: var(--accent); }

.chip-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.chip-toggle input { accent-color: var(--primary); }

.profile-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-soft);
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Receipt Review Line Items */
.rec-edit-row {
  display: grid;
  grid-template-columns: 1fr 78px 34px;
  gap: 6px;
  align-items: center;
  margin-bottom: 7px;
}

/* Bottom Sheet Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  background: var(--surface);
  border-top-left-radius: 26px;
  border-top-right-radius: 26px;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(10px + var(--safe-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
}
.modal-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--border);
  margin: 10px auto 4px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1.08rem; font-weight: 800; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.ing-list { list-style: none; padding: 0; margin: 0 0 14px; }
.ing-list li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.step-list { padding-left: 18px; margin: 0; }
.step-list li { margin-bottom: 8px; font-size: 0.92rem; }

/* Toast */
.toast {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: #181a1f;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  text-align: center;
}
.toast.error { background: #dc2626; }
