/* ── Theme ─────────────────────────────────────────────── */
:root {
  --ink:       #6A5A3C;
  --auburn:    #5A4A2C;
  --rust:      #BAA27A;
  --caramel:   #D2B9AF;
  --blush:     #E8D9CE;
  --parchment: #EDE9E2;
  --cream:     #F5F1EC;
  --divider:   #D8D0C7;
  --rest:      #7A9E7E;
  --batch:     #8FA8C8;
  --cook:      #C49A5A;
  --gf-warn:   #C28B45;
  --nav-h:     64px;
  --safe-bot:  env(safe-area-inset-bottom, 0px);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--parchment);
  color: var(--ink);
  overscroll-behavior: none;
  min-height: 100dvh;
}
button { background: none; border: none; cursor: pointer; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ── Typography ────────────────────────────────────────── */
h1, h2, h3 { font-family: Georgia, 'Times New Roman', serif; font-weight: normal; color: var(--auburn); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

/* ── Layout ────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0 0 calc(var(--nav-h) + var(--safe-bot)) 0;
}
.view {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.view.active { display: flex; }

.view-header {
  flex-shrink: 0;
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--divider);
  background: var(--parchment);
}
.view-title { line-height: 1.2; }
.view-subtitle { font-size: 0.8rem; color: var(--rust); display: block; margin-top: 2px; }

.view-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px 16px;
}

/* ── Bottom Nav ────────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  display: flex;
  background: var(--cream);
  border-top: 1px solid var(--divider);
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--caramel);
  padding: 6px 0;
  transition: color 0.15s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn span { font-size: 0.65rem; letter-spacing: 0.02em; }
.nav-btn.active { color: var(--auburn); }

/* ── Search ────────────────────────────────────────────── */
.search-input {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--blush);
  border: 1px solid var(--divider);
  border-radius: 10px;
  font-size: 1rem;   /* ≥16px or iOS Safari auto-zooms on focus */
  outline: none;
}
.search-input:focus { border-color: var(--rust); }

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid var(--divider);
  background: var(--parchment);
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--divider);
  font-size: 0.75rem;
  background: var(--cream);
  color: var(--ink);
  transition: background 0.15s, color 0.15s;
}
.filter-chip.active { background: var(--auburn); color: var(--cream); border-color: var(--auburn); }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--cream);
  border-radius: 14px;
  border: 1px solid var(--divider);
  padding: 14px;
  margin-bottom: 10px;
}
.card-tap { cursor: pointer; transition: opacity 0.1s; }
.card-tap:active { opacity: 0.75; }

.recipe-card-name { font-family: Georgia, serif; font-size: 1rem; color: var(--auburn); margin-bottom: 6px; }
.recipe-card-meta { font-size: 0.75rem; color: var(--rust); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.recipe-card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ── Tags / Chips ───────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.03em;
}
.tag-free  { background: #d4edda; color: #2d6a4f; }
.tag-batch { background: #dbe8f5; color: #4a6fa5; }
.tag-cook  { background: #fdebd0; color: #8b5e00; }
.tag-otg   { background: var(--blush); color: var(--auburn); }
.tag-quick { background: #f0ebe4; color: var(--ink); }
.tag-family{ background: #f5eef8; color: #6c3483; }
.tag-gf    { background: #fff3cd; color: #856404; border: 1px solid var(--gf-warn); }

/* ── Today view ─────────────────────────────────────────── */
.today-day-type {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 12px;
}
.day-training { background: #dbe8f5; color: #4a6fa5; }
.day-rest     { background: #d4edda; color: #2d6a4f; }

.meal-slot {
  background: var(--cream);
  border-radius: 14px;
  border: 1px solid var(--divider);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.1s;
}
.meal-slot:active { opacity: 0.75; }
.meal-slot-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--divider);
}
.meal-slot-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rust);
  flex: 1;
}
.meal-slot-badge {
  font-size: 0.65rem;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--blush);
  color: var(--ink);
}
.batch-badge  { background: #dbe8f5; color: #4a6fa5; }
.cook-badge   { background: #fdebd0; color: #8b5e00; }
.meal-slot-body { padding: 10px 14px; }
.meal-slot-name { font-family: Georgia, serif; font-size: 0.95rem; color: var(--auburn); }
.meal-slot-time { font-size: 0.75rem; color: var(--rust); margin-top: 3px; }

.snacks-card {
  background: var(--blush);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--ink);
}
.snacks-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 4px;
}

.shopping-btn {
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  background: var(--auburn);
  color: var(--cream);
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.02em;
  transition: opacity 0.15s;
}
.shopping-btn:active { opacity: 0.8; }

/* ── Week view ──────────────────────────────────────────── */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.week-nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blush);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--auburn);
}
.week-nav-btn svg { width: 18px; height: 18px; }
.week-nav-label { font-family: Georgia, serif; font-size: 1rem; color: var(--auburn); }

.day-row {
  background: var(--cream);
  border-radius: 14px;
  border: 1px solid var(--divider);
  margin-bottom: 8px;
  overflow: hidden;
}
.day-row-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--divider);
  gap: 8px;
}
.day-row-name { font-family: Georgia, serif; font-size: 0.95rem; flex: 1; }
.day-row-type { font-size: 0.68rem; padding: 2px 8px; border-radius: 10px; }
.day-row-chevron { width: 18px; height: 18px; color: var(--caramel); transition: transform 0.2s; }
.day-row.open .day-row-chevron { transform: rotate(90deg); }
.day-row-meals { display: none; padding: 8px 14px 12px; }
.day-row.open .day-row-meals { display: block; }
.day-meal-line {
  display: flex;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--divider);
  align-items: flex-start;
  cursor: pointer;
}
.day-meal-line:last-child { border-bottom: none; }
.day-meal-type {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--rust);
  width: 52px;
  flex-shrink: 0;
  padding-top: 2px;
}
.day-meal-name { font-size: 0.85rem; flex: 1; }
.day-meal-batch { font-size: 0.65rem; color: var(--batch); margin-top: 2px; }

/* ── Recipe drawer ──────────────────────────────────────── */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
.drawer.open { display: block; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(90,74,44,0.08);
}
.drawer-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  max-height: 90dvh;
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--divider);
  box-shadow: 0 -8px 32px rgba(90,74,44,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer.open .drawer-sheet { animation: sheet-up 0.25s ease-out; }
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.drawer-handle {
  flex-shrink: 0;
  width: 36px;
  height: 4px;
  background: var(--divider);
  border-radius: 2px;
  margin: 10px auto 0;
}
.drawer-body {
  flex: 1;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px calc(24px + var(--safe-bot));
}

.recipe-detail-name { font-size: 1.4rem; margin-bottom: 4px; }
.recipe-detail-meta { font-size: 0.8rem; color: var(--rust); display: flex; gap: 12px; margin-bottom: 12px; }
.recipe-detail-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }

.recipe-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rust);
  margin: 16px 0 8px;
}
.ingredient-list { list-style: none; }
.ingredient-item {
  display: flex;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 0.88rem;
  align-items: baseline;
}
.ingredient-item:last-child { border-bottom: none; }
.ingredient-qty { color: var(--rust); font-size: 0.82rem; min-width: 70px; flex-shrink: 0; }
.ingredient-gf::after { content: " ✓GF"; font-size: 0.65rem; color: var(--gf-warn); }

.method-list { counter-reset: step; list-style: none; }
.method-step {
  counter-increment: step;
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.method-step::before {
  content: counter(step);
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  background: var(--blush);
  color: var(--auburn);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 1px;
}

.adaptation-item {
  font-size: 0.82rem;
  padding: 5px 0;
  border-bottom: 1px solid var(--divider);
}
.adaptation-item:last-child { border-bottom: none; }
.adaptation-orig { text-decoration: line-through; color: var(--caramel); }
.adaptation-swap { color: var(--ink); margin-top: 2px; }
.adaptation-arrow { color: var(--rust); margin: 0 4px; }

.gf-check-box {
  background: #fff8e1;
  border: 1px solid var(--gf-warn);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 8px;
}
.gf-check-box ul { list-style: disc; padding-left: 18px; font-size: 0.82rem; }

.serving-note {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--blush);
  border-radius: 10px;
  font-size: 0.82rem;
  color: var(--ink);
  font-style: italic;
}

/* ── Shopping modal ──────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
}
.modal.open { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: rgba(90,74,44,0.08);
}
.modal-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  max-height: 92dvh;
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--divider);
  box-shadow: 0 -8px 32px rgba(90,74,44,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.open .modal-sheet { animation: sheet-up 0.25s ease-out; }
.modal-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--divider);
}
.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blush);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.modal-body {
  flex: 1;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding: 12px 20px calc(20px + var(--safe-bot));
}

.shop-section { margin-bottom: 20px; }
.shop-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--divider);
}
.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--divider);
  gap: 10px;
}
.shop-item:last-child { border-bottom: none; }
.shop-item { cursor: pointer; }
.shop-item.checked { opacity: 0.45; }
.shop-item.checked .shop-item-name,
.shop-item.checked .shop-item-qty { text-decoration: line-through; }
.shop-item-name { flex: 1; }
.shop-item-qty { color: var(--rust); font-size: 0.82rem; text-align: right; white-space: nowrap; }
.shop-item-gf { font-size: 0.65rem; color: var(--gf-warn); margin-left: 4px; }

/* ── Build a Meal ─────────────────────────────────────────── */
.build-section { margin-bottom: 20px; }
.build-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 8px;
}
.build-type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.type-btn {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1.5px solid var(--divider);
  font-size: 0.82rem;
  text-align: center;
  background: var(--cream);
  transition: background 0.15s;
}
.type-btn.active { background: var(--auburn); color: var(--cream); border-color: var(--auburn); }

.picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.picker-item {
  padding: 10px;
  border-radius: 12px;
  border: 1.5px solid var(--divider);
  font-size: 0.82rem;
  text-align: center;
  background: var(--cream);
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.picker-item.selected { background: var(--blush); border-color: var(--auburn); color: var(--auburn); }

.build-veg-grid { grid-template-columns: repeat(3, 1fr); }

.build-generate-btn {
  width: 100%;
  padding: 14px;
  background: var(--auburn);
  color: var(--cream);
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  margin-top: 8px;
  transition: opacity 0.15s;
}
.build-generate-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.build-generate-btn:active:not(:disabled) { opacity: 0.8; }

.build-result {
  margin-top: 16px;
  background: var(--cream);
  border-radius: 14px;
  border: 1px solid var(--divider);
  padding: 16px;
}
.build-result-name { font-family: Georgia, serif; font-size: 1.1rem; margin-bottom: 12px; }

/* ── Settings ─────────────────────────────────────────────── */
.settings-group { margin-bottom: 24px; }
.settings-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rust);
  margin-bottom: 10px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--cream);
  border-radius: 12px;
  border: 1px solid var(--divider);
  margin-bottom: 8px;
  font-size: 0.9rem;
}
.settings-row-label { flex: 1; }
.settings-row-value { color: var(--rust); font-size: 0.82rem; }

.toggle-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.day-toggle {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--divider);
  font-size: 0.8rem;
  background: var(--cream);
  cursor: pointer;
  transition: background 0.15s;
}
.day-toggle.active { background: var(--auburn); color: var(--cream); border-color: var(--auburn); }

.settings-btn {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  text-align: center;
  border: 1.5px solid var(--divider);
  background: var(--cream);
  margin-bottom: 8px;
  transition: background 0.15s;
}
.settings-btn:active { background: var(--blush); }
.settings-btn-danger { border-color: #e74c3c; color: #c0392b; }

/* ── Cycle progress bar ───────────────────────────────────── */
.progress-bar-track {
  height: 6px;
  background: var(--blush);
  border-radius: 3px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--rust);
  border-radius: 3px;
  transition: width 0.4s ease;
}
.progress-label {
  font-size: 0.75rem;
  color: var(--rust);
  display: flex;
  justify-content: space-between;
}

/* ── Onboarding ───────────────────────────────────────────── */
.onboarding {
  position: fixed;
  inset: 0;
  background: var(--parchment);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.onboarding[aria-hidden="true"] { display: none; }
.onboarding-card {
  width: 100%;
  max-width: 360px;
  background: var(--cream);
  border-radius: 20px;
  padding: 28px 24px;
  border: 1px solid var(--divider);
}
.onboarding-title { font-size: 1.5rem; margin-bottom: 6px; text-align: center; }
.onboarding-sub { text-align: center; color: var(--rust); font-size: 0.85rem; margin-bottom: 24px; }
.onboarding-label { font-size: 0.8rem; color: var(--rust); margin-bottom: 6px; }
.onboarding-field {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--divider);
  border-radius: 10px;
  background: var(--parchment);
  margin-bottom: 16px;
  font-size: 1rem;   /* ≥16px or iOS Safari auto-zooms on focus */
}
.onboarding-field:focus { outline: none; border-color: var(--rust); }
.onboarding-next-btn {
  width: 100%;
  padding: 13px;
  background: var(--auburn);
  color: var(--cream);
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  margin-top: 8px;
  transition: opacity 0.15s;
}
.onboarding-next-btn:active { opacity: 0.8; }
.cycle-option {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}
.cycle-option input[type="radio"] { margin-top: 3px; accent-color: var(--auburn); }
.cycle-option-label { font-size: 0.9rem; }
.cycle-option-sub { font-size: 0.75rem; color: var(--rust); }

/* ── Empty / loading states ──────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--caramel);
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 8px; }
.empty-state p { font-size: 0.85rem; }

/* ── Utility ──────────────────────────────────────────────── */
.divider { height: 1px; background: var(--divider); margin: 12px 0; }
.text-sm { font-size: 0.82rem; }
.text-muted { color: var(--rust); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
