*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange: #d4622b;
  --orange-light: #e07840;
  --orange-dim: rgba(212, 98, 43, 0.1);
  --green: #6b9e78;
  --green-light: #7db88a;
  --green-dim: rgba(107, 158, 120, 0.1);
  --purple: #7b6ea7;
  --purple-light: #9488bb;
  --purple-dim: rgba(123, 110, 167, 0.1);
  --bg: #faf8f5;
  --card: #ffffff;
  --text: #2d2d2d;
  --text-muted: #8a8580;
  --border: #e8e4de;
  --border-light: #f0ece6;
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 52px;
  --tab-height: 56px;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.screen { height: 100%; width: 100%; position: absolute; top: 0; left: 0; }
.screen[hidden] { display: none !important; }

/* ── Auth Screen ───────────────────────────── */

#auth-screen {
  background: linear-gradient(160deg, #d4622b 0%, #b8481a 100%);
  display: flex; align-items: center; justify-content: center;
}
.auth-container { text-align: center; padding: 24px; width: 100%; max-width: 320px; }
.auth-icon { font-size: 56px; margin-bottom: 12px; }
.auth-title { color: #fff; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.auth-subtitle { color: rgba(255,255,255,0.7); font-size: 15px; margin-top: 4px; margin-bottom: 28px; }

.pin-display { display: flex; gap: 14px; justify-content: center; margin-bottom: 32px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  transition: all 0.15s ease;
}
.pin-dot.filled { background: #fff; border-color: #fff; }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 260px; margin: 0 auto; }
.pin-key {
  height: 56px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.15); color: #fff;
  font-size: 22px; font-weight: 500; font-family: var(--font);
  cursor: pointer; transition: background 0.1s;
  -webkit-user-select: none; user-select: none;
}
.pin-key:active { background: rgba(255,255,255,0.3); }
.pin-key:disabled { background: transparent; cursor: default; }
.pin-delete { font-size: 20px; }

.auth-error { color: rgba(255,255,255,0.9); font-size: 14px; margin-top: 16px; }

/* ── App Shell ─────────────────────────────── */

#app { display: flex; flex-direction: column; background: var(--bg); }

#top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 20px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0; z-index: 10;
}
#header-title { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.header-week { font-size: 13px; color: var(--text-muted); font-weight: 500; }

#views {
  flex: 1; overflow: hidden; position: relative;
}
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.view-scroll {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tab-height) + var(--safe-bottom) + 16px);
}

#tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--card);
  border-top: 1px solid var(--border-light);
  padding: 6px 0 calc(var(--safe-bottom) + 6px);
  z-index: 10;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: none; background: none; color: var(--text-muted);
  font-size: 10px; font-weight: 600; font-family: var(--font);
  padding: 4px 0; cursor: pointer; transition: color 0.15s;
  -webkit-user-select: none; user-select: none;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--orange); }

/* ── Cards & Series ────────────────────────── */

.series-block { margin-bottom: 20px; }
.series-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.series-header.s1 { background: var(--orange-dim); color: var(--orange); }
.series-header.s2 { background: var(--green-dim); color: var(--green); }
.series-header.s3 { background: var(--purple-dim); color: var(--purple); }
.series-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.series-cost { font-size: 13px; font-weight: 600; }
.series-chevron { font-size: 14px; transition: transform 0.2s; }
.series-header.collapsed .series-chevron { transform: rotate(-90deg); }

.meal-card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border-light);
  margin-bottom: 8px; overflow: hidden;
  transition: box-shadow 0.15s;
}
.meal-card-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.day-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 3px 8px; border-radius: 4px; color: #fff;
  flex-shrink: 0; min-width: 36px; text-align: center;
}
.day-badge.s1 { background: var(--orange); }
.day-badge.s2 { background: var(--green); }
.day-badge.s3 { background: var(--purple); }
.meal-name { font-size: 15px; font-weight: 600; flex: 1; }
.meal-time { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.meal-detail { display: none; padding: 0 16px 16px; border-top: 1px solid var(--border-light); }
.meal-card.expanded .meal-detail { display: block; padding-top: 14px; }

.detail-section { margin-bottom: 12px; }
.detail-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 4px;
}
.detail-text { font-size: 14px; line-height: 1.5; color: var(--text); }
.detail-ingredients { list-style: none; }
.detail-ingredients li { font-size: 14px; line-height: 1.6; padding-left: 16px; position: relative; }
.detail-ingredients li::before { content: '·'; position: absolute; left: 4px; color: var(--text-muted); }

.toddler-tip {
  background: #fef9f3; border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; line-height: 1.4; color: #8b5e3c;
}

.btn-swap {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 14px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; font-family: var(--font); margin-top: 4px;
}
.btn-swap:active { background: var(--border-light); }

/* ── Grocery ───────────────────────────────── */

#grocery-progress-wrap {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.progress-bar {
  flex: 1; height: 8px; background: var(--border-light);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--green); border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-label { font-size: 13px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

.grocery-series { margin-bottom: 20px; }
.grocery-series-header {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; padding: 8px 0; margin-bottom: 4px;
}
.grocery-series-header.s1 { color: var(--orange); }
.grocery-series-header.s2 { color: var(--green); }
.grocery-series-header.s3 { color: var(--purple); }

.grocery-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  padding: 8px 0 4px;
}

.grocery-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border-light);
  cursor: pointer; -webkit-user-select: none; user-select: none;
}
.grocery-check {
  width: 22px; height: 22px; border-radius: 6px;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
.grocery-item.checked .grocery-check {
  background: var(--green); border-color: var(--green);
}
.grocery-item.checked .grocery-check::after {
  content: '✓'; color: #fff; font-size: 13px; font-weight: 700;
}
.grocery-item-text { font-size: 15px; flex: 1; transition: all 0.15s; }
.grocery-item-qty { font-size: 13px; color: var(--text-muted); }
.grocery-item.checked .grocery-item-text {
  text-decoration: line-through; color: var(--text-muted);
}

/* ── Savings ───────────────────────────────── */

.savings-card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid var(--border-light);
  padding: 20px; margin-bottom: 16px;
}
.savings-big {
  font-size: 36px; font-weight: 800; color: var(--green);
  letter-spacing: -1px;
}
.savings-label { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-top: 2px; }

.savings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border-light);
}
.savings-row:last-child { border-bottom: none; }
.savings-row-label { font-size: 14px; color: var(--text); }
.savings-row-value { font-size: 14px; font-weight: 600; }

.chart-bar-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.chart-label { font-size: 12px; color: var(--text-muted); width: 50px; text-align: right; }
.chart-bar-wrap { flex: 1; height: 24px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.chart-bar {
  height: 100%; border-radius: 4px; display: flex;
  align-items: center; padding-left: 8px;
  font-size: 11px; font-weight: 700; color: #fff;
  transition: width 0.5s ease;
}
.chart-bar.green { background: var(--green); }

.savings-total-card {
  background: linear-gradient(135deg, var(--green) 0%, #5a8a67 100%);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  text-align: center; color: #fff;
}
.savings-total-card .savings-big { color: #fff; font-size: 42px; }
.savings-total-card .savings-label { color: rgba(255,255,255,0.8); }

/* ── Feedback ──────────────────────────────── */

.feedback-form { padding-bottom: 24px; }
.feedback-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.field { margin: 16px 0; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
}
.field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-family: var(--font);
  background: var(--card); color: var(--text);
  -webkit-appearance: none;
}
.field textarea { resize: vertical; min-height: 80px; }

.btn-primary {
  width: 100%; padding: 14px; border: none;
  background: var(--orange); color: #fff;
  font-size: 16px; font-weight: 600; font-family: var(--font);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

#feedback-status {
  text-align: center; padding: 12px;
  font-size: 14px; font-weight: 600; color: var(--green);
  margin-top: 12px;
}

.feedback-item {
  background: var(--card); border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  padding: 12px 14px; margin-bottom: 8px;
}
.feedback-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.feedback-msg { font-size: 14px; line-height: 1.4; }

/* ── Swap Modal ───────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.modal-overlay[hidden] { display: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-sheet {
  background: var(--bg); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 500px;
  max-height: 85vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
  animation: slideUp 0.25s ease;
}

.swap-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
.swap-header h3 { font-size: 17px; font-weight: 700; margin: 0; flex: 1; text-align: center; }
.swap-close {
  background: none; border: none; font-size: 18px; color: var(--text-muted);
  cursor: pointer; padding: 4px 8px; flex-shrink: 0;
}

.swap-mode-btn {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 16px; margin-bottom: 10px;
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); cursor: pointer;
  font-family: var(--font); text-align: left;
  transition: border-color 0.15s;
}
.swap-mode-btn:active { border-color: var(--orange); }
.swap-mode-icon { font-size: 24px; flex-shrink: 0; }
.swap-mode-label { font-size: 15px; font-weight: 600; color: var(--text); }
.swap-mode-desc { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.swap-cancel {
  display: block; width: 100%; padding: 14px;
  background: none; border: none; color: var(--text-muted);
  font-size: 15px; font-weight: 600; font-family: var(--font);
  cursor: pointer; text-align: center; margin-top: 4px;
}

.swap-back {
  background: none; border: none; font-size: 20px;
  color: var(--orange); font-weight: 600; font-family: var(--font);
  cursor: pointer; padding: 4px 8px; flex-shrink: 0;
}

/* Recipe cards */
.recipe-category { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); padding: 12px 0 6px; }
.recipe-card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 12px 14px;
  margin-bottom: 6px; cursor: pointer; transition: border-color 0.15s;
  font-family: var(--font);
}
.recipe-card:active { border-color: var(--orange); }
.recipe-card-name { font-size: 14px; font-weight: 600; }
.recipe-card-notes { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.recipe-card-compat { font-size: 12px; color: var(--orange); white-space: nowrap; }

.recipe-card-top { display: flex; justify-content: space-between; align-items: center; }
.recipe-compat { color: var(--orange); font-size: 13px; flex-shrink: 0; margin-left: 8px; }
.recipe-category-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); padding: 14px 0 6px;
}
.recipe-list { max-height: 55vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Swap loading & custom */
.swap-loading { padding: 20px 0; }
.swap-loading-text { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 12px; }
.swap-custom { padding: 8px 0; }
.swap-custom-hint { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.swap-generate-btn { margin-top: 0; }
.swap-confirm-btn { width: 100%; margin-top: 16px; }
.swap-confirm-meta { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; display: flex; gap: 16px; flex-wrap: wrap; }
.w60 { width: 60%; }
.w70 { width: 70%; }
.w80 { width: 80%; }
.w90 { width: 90%; }

/* Suggestion cards */
.suggestion-list { max-height: 55vh; overflow-y: auto; }
.suggestion-card {
  display: block; width: 100%; text-align: left; font-family: var(--font);
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
  cursor: pointer; transition: border-color 0.15s;
}
.suggestion-card:active { border-color: var(--orange); }
.suggestion-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.suggestion-shared { font-size: 12px; color: var(--green); margin-bottom: 4px; }
.suggestion-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.suggestion-ingredients { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.suggestion-pick {
  background: var(--orange); color: #fff; border: none;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: var(--font);
  cursor: pointer; float: right;
}
.suggestion-pick:active { opacity: 0.85; }

/* Custom swap */
.swap-textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; font-family: var(--font);
  background: var(--card); color: var(--text); resize: vertical;
  min-height: 80px; margin-bottom: 14px;
}

/* Confirmation */
.swap-confirm-meal {
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.swap-confirm-name { font-size: 17px; font-weight: 700; margin-bottom: 12px; }

/* Loading skeleton */
.skeleton-card {
  background: var(--card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 16px; margin-bottom: 10px;
}
.skeleton-line {
  height: 14px; border-radius: 4px; margin-bottom: 8px;
  background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-line:nth-child(1) { width: 70%; height: 18px; }
.skeleton-line:nth-child(2) { width: 50%; }
.skeleton-line:nth-child(3) { width: 85%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.swap-error {
  text-align: center; padding: 20px;
  color: var(--orange); font-size: 14px; font-weight: 600;
}
.swap-error button {
  display: inline-block; margin-top: 8px;
  background: var(--orange); color: #fff; border: none;
  padding: 8px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: var(--font);
  cursor: pointer;
}

/* ── Utilities ─────────────────────────────── */

.text-muted { color: var(--text-muted); }
.empty-state {
  text-align: center; padding: 60px 20px;
  font-size: 15px; color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917;
    --card: #252422;
    --text: #e8e4de;
    --text-muted: #8a8580;
    --border: #3a3835;
    --border-light: #2e2c2a;
  }
  #auth-screen { background: linear-gradient(160deg, #b8481a 0%, #8a3510 100%); }
  .toddler-tip { background: #2e2820; color: #c9a67a; }
}
