@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ============================================================
   CSS Variables
   ============================================================ */
:root {
  --cream: #FFFFFF;
  --cream-dark: #F5F5F2;
  --yellow: #FFD166;
  --yellow-light: #FFF4DC;
  --yellow-dark: #B88A00;
  --green: #72CFBA;
  --green-light: #CCF0E8;
  --green-dark: #3AAD96;
  --blue: #8BBCC0;
  --blue-light: #E8F4F5;
  --beige: #C4B5A5;
  --beige-light: #F5EFE8;
  --red: #D4705A;
  --red-light: #FAE8E4;
  --text: #2A2A2A;
  --text-light: #4A6A5E;
  --text-muted: #9AB8AD;
  --bg: #FFFFFF;
  --card: #FFFFFF;
  --border: #C8E8D8;
  --shadow: 0 2px 20px rgba(80,170,130,0.12);
  --shadow-lg: 0 8px 40px rgba(80,170,130,0.18);
  --radius: 24px;
  --radius-sm: 16px;
  --header-h: 60px;
  --nav-h: 68px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'Nunito', 'Avenir Next', 'Avenir', 'Trebuchet MS', sans-serif;
  background: var(--cream);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.5;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; outline: none; }
a { color: inherit; text-decoration: none; }

/* ============================================================
   Setup Screen
   ============================================================ */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--cream);
  z-index: 100;
  padding: 24px;
}

.setup-container {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center;
}

.setup-icon { font-size: 72px; line-height: 1; }
.setup-title { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -0.3px; }
.setup-subtitle { font-size: 15px; color: var(--text-light); margin-top: -8px; }

.divider {
  width: 100%; display: flex; align-items: center; gap: 12px;
  color: var(--text-muted); font-size: 14px;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.join-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.join-label { font-size: 14px; color: var(--text-light); text-align: left; }

.code-input {
  width: 100%; padding: 14px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; letter-spacing: 0;
  text-align: center;
  background: var(--card);
  transition: border-color 0.2s;
}
.code-input:focus { border-color: var(--green); }

/* ============================================================
   Main App Layout
   ============================================================ */
.hidden { display: none !important; }

#main-app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}

/* Header */
.app-header {
  height: var(--header-h);
  background: var(--cream);
  border-bottom: 2px solid var(--border);
  display: flex; align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}

.app-title {
  flex: 1;
  font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif;
  font-size: 22px; font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.header-right { display: flex; align-items: center; gap: 8px; }

/* Tab Content */
.tab-content {
  flex: 1; overflow: hidden; position: relative;
}

.tab-pane {
  position: absolute; inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 80px);
  display: none;
}
.tab-pane.active { display: block; }

/* Bottom Nav */
.bottom-nav {
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--cream);
  border-top: 2px solid var(--border);
  display: flex;
  flex-shrink: 0;
}

.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px; padding: 8px 0;
  color: var(--text-muted);
  transition: color 0.2s;
  min-height: 44px;
}
.nav-item.active { color: var(--green-dark); }
.nav-icon { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; }
.nav-label { font-size: 11px; font-weight: 600; }

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  display: flex; gap: 8px;
  padding: 12px 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text-light);
  padding: 8px 18px;
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 5px;
}
.filter-pill.active {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #7A5800;
  font-weight: 700;
}

/* ============================================================
   Shopping List
   ============================================================ */
.complete-bar {
  margin: 0 16px 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.btn-complete {
  width: 100%; padding: 14px;
  background: var(--green); color: #fff;
  font-size: 16px; font-weight: 700;
  border-radius: var(--radius-sm);
  transition: opacity 0.2s;
}
.btn-complete:active { opacity: 0.8; }

.items-container { padding: 0 16px 8px; }

/* Category Section */
.category-section { margin-bottom: 12px; }

.category-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
  user-select: none;
}
.category-header:active { opacity: 0.7; }

.cat-icon { display:flex; align-items:center; flex-shrink:0; color: var(--text-light); }

.cat-name {
  font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif;
  font-size: 17px; font-weight: 700;
  color: var(--text); flex: 1;
  position: relative;
}
/* アクセントラインをcat-nameの下に */
.cat-name::after {
  content: '';
  display: block;
  width: 40px; height: 4px;
  border-radius: 2px;
  margin-top: 3px;
}
.cat-Vegetables .cat-name::after { background: var(--green); }
.cat-Meat---Fish .cat-name::after { background: var(--red); }
.cat-Dairy---Eggs .cat-name::after { background: var(--yellow); }
.cat-Soy---Beans .cat-name::after { background: var(--beige); }
.cat-Seasoning .cat-name::after { background: var(--yellow); }
.cat-Daily .cat-name::after { background: var(--beige); }
.cat-Food .cat-name::after { background: var(--green); }
.cat-Mochi---Milou .cat-name::after { background: var(--blue); }
.cat-Nikotaro .cat-name::after { background: var(--yellow); }

.cat-count {
  font-size: 13px; color: var(--text-muted);
  background: var(--cream-dark); padding: 2px 8px; border-radius: 10px;
}
.cat-chevron {
  color: var(--text-muted); font-size: 18px;
  transition: transform 0.2s;
}
.cat-chevron.open { transform: rotate(90deg); }

.category-items { margin-top: 2px; display: none; }
.category-items.open { display: block; }

/* Item Card */
.item-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 8px rgba(180,160,120,0.08);
  transition: all 0.2s;
}
.item-card.in-stock { background: var(--green-light); border-color: #C8E6C0; }
.item-card.need-buy { background: var(--card); }

.item-tap-area {
  display: flex; align-items: center; gap: 12px;
  flex: 1; min-width: 0;
  cursor: pointer; padding: 4px 0;
}

/* チェックボックス（大きめ・かわいい） */
.item-checkbox {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  border: 2.5px solid #B2D9C8;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; background: var(--card);
  cursor: pointer; position: relative;
}
.item-checkbox.checked {
  background: var(--yellow);
  border-color: var(--yellow);
  /* にこちゃん：目と口をSVGで描画 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='35' cy='40' r='8' fill='%23B88A00'/%3E%3Ccircle cx='65' cy='40' r='8' fill='%23B88A00'/%3E%3Cpath d='M28 62 Q50 80 72 62' fill='none' stroke='%23B88A00' stroke-width='10' stroke-linecap='round'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.item-checkbox.checked::before,
.item-checkbox.checked::after { display: none; }

.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 16px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-name.in-stock { color: var(--text-muted); }
.item-qty { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* In Stock バッジ（チェックされたとき） */
.stock-badge {
  font-size: 11px; font-weight: 700; padding: 3px 10px;
  background: var(--green-dark); color: white;
  border-radius: 12px; flex-shrink: 0;
}

.item-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}
.btn-icon:active { opacity: 0.7; }
.btn-icon-edit { color: var(--text-muted); }
.btn-icon-edit:active { background: var(--cream-dark); }

/* Empty State */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 17px; font-weight: 700; color: var(--text-light); }
.empty-state-sub { font-size: 14px; margin-top: 6px; }

/* FAB */
.fab {
  position: fixed; right: 20px;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--yellow); color: white;
  font-size: 28px; font-weight: 300;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(255,209,102,0.5);
  transition: transform 0.15s;
  z-index: 10;
}
.fab:active { transform: scale(0.92); }

/* ============================================================
   Meal Plan
   ============================================================ */
.week-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px;
}

.week-nav-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  color: var(--text); font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.week-nav-btn:active { background: var(--cream-dark); }

.week-label { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 15px; font-weight: 700; color: var(--text); }

.generate-bar {
  display: flex; gap: 8px;
  padding: 0 16px 8px;
}

.btn-generate {
  flex: 1; padding: 14px 16px;
  background: var(--green-dark); color: white;
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 700;
  transition: opacity 0.2s;
}
.btn-generate:active { opacity: 0.8; }

.btn-generate-sm {
  padding: 14px 16px;
  background: var(--yellow-light); color: var(--yellow-dark);
  border: 2px solid var(--yellow);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  transition: opacity 0.2s;
}
.btn-generate-sm:active { opacity: 0.8; }

.meal-plan-container { padding: 0 16px; }

.day-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.day-card.today { border: 2.5px solid var(--yellow); }

.day-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.day-name {
  font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif;
  font-size: 18px; font-weight: 700;
  width: 32px; text-align: center;
}
.day-name.saturday { color: var(--blue); }
.day-name.sunday { color: var(--red); }
.day-date { font-size: 13px; color: var(--text-muted); }
.today-badge {
  background: var(--yellow); color: var(--text);
  font-size: 11px; font-weight: 700;
  padding: 3px 10px; border-radius: 12px;
  margin-left: auto;
}

.day-meals { display: flex; flex-direction: column; }

.meal-slot {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; transition: background 0.15s;
}
.meal-slot:last-child { border-bottom: none; }
.meal-slot:active { background: var(--cream-dark); }

.meal-type-badge {
  width: 32px; height: 32px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; flex-shrink: 0;
}
.badge-breakfast { background: var(--yellow-light); color: var(--yellow-dark); }
.badge-lunch { background: var(--yellow-light); color: var(--yellow-dark); }
.badge-dinner { background: var(--green-light); color: var(--green-dark); }

.meal-recipe-name {
  flex: 1; font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meal-slot-content { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.meal-side-dish { font-size: 12px; color: var(--text-muted); }
.side-empty { color: var(--text-muted); font-style: italic; }
.meal-empty { flex: 1; font-size: 14px; color: var(--text-muted); font-style: italic; }

.meal-del-btn {
  width: 28px; height: 28px; border-radius: 50%;
  color: var(--text-muted); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
}
.meal-del-btn:active { background: var(--red-light); color: var(--red); }

.add-to-shopping-bar {
  padding: 8px 16px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.btn-add-to-shopping {
  width: 100%; padding: 16px;
  background: var(--yellow-light); color: var(--yellow-dark);
  border: 2px solid var(--yellow);
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 700;
  transition: opacity 0.2s;
}
.btn-add-to-shopping:active { opacity: 0.8; }
.btn-clear-week {
  width: 100%; padding: 10px;
  background: none; color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  transition: opacity 0.2s;
}
.btn-clear-week:active { background: var(--cream-dark); }

/* ============================================================
   Recipe Finder
   ============================================================ */
.finder-section { padding: 16px 16px 8px; }
.finder-title {
  font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif;
  font-size: 17px; font-weight: 700;
  color: var(--text); margin-bottom: 12px;
}
.finder-title span {
  display: inline-block;
  width: 6px; height: 6px;
  background: var(--yellow); border-radius: 50%;
  margin-right: 8px; vertical-align: middle;
}

.ingredient-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ing-chip {
  padding: 8px 14px; border-radius: 20px;
  border: 2px solid var(--border); background: var(--card);
  font-size: 14px; font-weight: 600; color: var(--text-light);
  cursor: pointer; transition: all 0.15s;
  user-select: none;
}
.ing-chip.selected { background: var(--yellow); border-color: var(--yellow); color: var(--text); }

.method-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.method-chip {
  padding: 10px 16px; border-radius: 20px;
  border: 2px solid var(--border); background: var(--card);
  font-size: 14px; font-weight: 600; color: var(--text-light);
  cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; gap: 5px;
}
.method-chip.selected { background: var(--green); border-color: var(--green); color: white; }

.finder-results { padding: 8px 16px 16px; }
.finder-result-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 10px; box-shadow: var(--shadow);
  cursor: pointer;
}
.finder-result-card:active { opacity: 0.85; }
.finder-result-name { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.match-score { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.match-dots { display: flex; gap: 3px; }
.match-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.match-dot.filled { background: var(--green); }
.match-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.finder-result-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.method-tag { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 12px; background: var(--green-light); color: var(--green-dark); }
.ing-match-tag { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--yellow-light); color: var(--yellow-dark); }
.no-results { text-align: center; padding: 40px 24px; color: var(--text-muted); }
.no-results-icon { font-size: 48px; margin-bottom: 12px; }

.finder-divider { border: none; border-top: 2px dashed var(--border); margin: 8px 16px; }

/* ============================================================
   Recipes (legacy card, used in meal modal)
   ============================================================ */
.search-wrap { padding: 12px 16px 0; }
.search-input-wrap {
  position: relative; width: 100%;
}
.search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.search-input {
  width: 100%; padding: 12px 16px 12px 40px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 15px; font-family: inherit;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--green); outline: none; }

.recipes-container { padding: 8px 16px; }

.recipe-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
  cursor: pointer;
  transition: transform 0.15s;
}
.recipe-card:active { transform: scale(0.98); }

.recipe-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.recipe-card-name { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 16px; font-weight: 700; flex: 1; }
.recipe-card-edit {
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--text-muted); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.recipe-card-edit:active { background: var(--cream-dark); }

.recipe-meta { display: flex; align-items: center; gap: 12px; }
.recipe-meta-item { font-size: 13px; color: var(--text-muted); }

.recipe-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.recipe-tag {
  font-size: 11px; font-weight: 600; padding: 3px 8px;
  border-radius: 10px; background: var(--green-light); color: var(--green-dark);
}
.recipe-type-tag {
  font-size: 11px; font-weight: 600; padding: 3px 8px;
  border-radius: 10px; background: var(--blue-light); color: #2D6B8A;
}

/* ============================================================
   Settings
   ============================================================ */
.settings-container { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.settings-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}

.settings-section-title { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 17px; font-weight: 700; color: var(--text); }
.settings-desc { font-size: 14px; color: var(--text-light); line-height: 1.6; }
.settings-hint { font-size: 13px; color: var(--text-muted); background: var(--cream-dark); padding: 10px 12px; border-radius: 8px; }

.code-share-box {
  display: flex; align-items: center; gap: 12px;
  background: var(--cream-dark); border-radius: var(--radius-sm);
  padding: 12px 16px;
}
.code-display {
  flex: 1; font-size: 28px; font-weight: 800;
  letter-spacing: 6px; color: var(--green-dark);
  text-align: center;
}
.btn-copy {
  padding: 8px 16px;
  background: var(--green); color: #fff;
  border-radius: 8px; font-size: 14px; font-weight: 700;
  transition: opacity 0.2s;
}
.btn-copy:active { opacity: 0.8; }

.join-form-row { display: flex; gap: 8px; }
.code-input-sm {
  flex: 1; padding: 12px 14px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 18px; font-weight: 700; letter-spacing: 3px;
  text-align: center; text-transform: uppercase;
  transition: border-color 0.2s;
}
.code-input-sm:focus { border-color: var(--green); }

/* ============================================================
   Modals
   ============================================================ */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  /* iOSキーボード対応 */
  top: env(safe-area-inset-top, 0px);
}

.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.35);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  position: relative; z-index: 1;
  width: 100%; max-width: 540px;
  background: var(--cream);
  border-radius: 28px 28px 0 0;
  transition: max-height 0.2s ease;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: slideUp 0.3s ease;
}

.modal-sheet-tall { max-height: 95vh; }

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

.modal-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 8px;
}
.modal-header h2 { font-family: 'Nunito', 'Avenir Next', 'Avenir', sans-serif; font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--cream-dark); color: var(--text-muted);
  font-size: 18px; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.modal-close:active { background: var(--border); }

/* Forms */
.form-group { padding: 0 20px 12px; }
.form-label { display: block; font-size: 13px; font-weight: 700; color: var(--text-light); margin-bottom: 6px; }
.required { color: var(--red); }

.form-input {
  width: 100%; padding: 13px 15px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); font-size: 16px;
  transition: border-color 0.2s;
}
.form-input:focus { border-color: var(--green); }

.form-select {
  width: 100%; padding: 13px 15px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); font-size: 16px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M6 8L0 0h12z' fill='%23B0A898'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  transition: border-color 0.2s;
}
.form-select:focus { border-color: var(--green); }

.form-textarea {
  width: 100%; padding: 13px 15px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card); font-size: 15px;
  min-height: 80px; resize: vertical;
  transition: border-color 0.2s;
}
.form-textarea:focus { border-color: var(--green); }

.form-row { display: flex; gap: 0; padding: 0 20px 12px; }
.form-row .form-group { padding: 0; }
.form-row .form-group:first-child { padding-right: 6px; }
.form-row .form-group:last-child { padding-left: 6px; }
.flex-1 { flex: 1; }

.checkbox-row { display: flex; gap: 16px; flex-wrap: wrap; }
.check-label { display: flex; align-items: center; gap: 6px; font-size: 15px; cursor: pointer; padding: 4px 0; }
.check-label input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--green); }

.tag-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.tag-check { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; padding: 6px 0; }
.tag-check input { width: 18px; height: 18px; cursor: pointer; accent-color: var(--green); }

/* Ingredients */
.ingredient-row {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 0;
}
.ing-name {
  flex: 2; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--card); font-size: 15px;
}
.ing-name:focus { border-color: var(--green); }
.ing-qty {
  flex: 1; padding: 10px 8px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--card); font-size: 15px; text-align: center;
  min-width: 0;
}
.ing-qty:focus { border-color: var(--green); }
.ing-unit {
  flex: 1; padding: 10px 8px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--card); font-size: 15px;
  min-width: 0;
}
.ing-unit:focus { border-color: var(--green); }
.btn-del-ing {
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--text-muted); font-size: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.btn-del-ing:active { background: var(--red-light); color: var(--red); }

.btn-add-row {
  margin-top: 8px; padding: 10px 0;
  width: 100%; text-align: center;
  color: var(--green-dark); font-size: 14px; font-weight: 700;
  border: 1.5px dashed var(--green);
  border-radius: 8px; background: var(--green-light);
}

/* Form Actions */
.form-actions { padding: 8px 20px 4px; display: flex; flex-direction: column; gap: 8px; }

/* Buttons */
.btn-primary {
  padding: 15px;
  background: var(--green); color: white;
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  transition: opacity 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  padding: 15px;
  background: var(--card); color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  transition: background 0.15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-secondary:active { background: var(--cream-dark); }

.btn-danger {
  padding: 15px;
  background: var(--red-light); color: var(--red);
  border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700;
  transition: opacity 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-danger:active { opacity: 0.8; }

.btn-danger-outline {
  width: 100%; padding: 12px;
  background: transparent; color: var(--red);
  border: 1.5px solid var(--red);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  margin: 0 20px; width: calc(100% - 40px);
  display: block;
  transition: background 0.15s;
}
.btn-danger-outline:active { background: var(--red-light); }

.btn-large { width: 100%; padding: 16px; font-size: 17px; }
.btn-full { width: 100%; }

/* Meal Picker */
/* Recipe Detail View (in meal modal) */
.recipe-detail-content {
  padding: 4px 20px 8px;
  max-height: 55vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.detail-section {
  margin-bottom: 18px;
}
.detail-section-label {
  font-size: 11px; font-weight: 800; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}
.detail-ing-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.detail-ing-name { font-size: 15px; font-weight: 600; }
.detail-ing-qty { font-size: 14px; color: var(--text-muted); }
.detail-side-dish {
  padding: 10px 14px;
  background: var(--green-light); border-radius: 12px;
  font-size: 15px; font-weight: 700; color: var(--green-dark);
}
.detail-url-btn {
  display: block; padding: 14px 18px;
  background: var(--yellow-light);
  border: 1.5px solid var(--yellow);
  border-radius: var(--radius-sm);
  color: var(--yellow-dark); font-size: 15px; font-weight: 700;
  text-decoration: none; text-align: center;
  word-break: break-all;
  transition: opacity 0.15s;
}
.detail-url-btn:active { opacity: 0.7; }
.detail-notes {
  font-size: 14px; color: var(--text-light); line-height: 1.6;
  white-space: pre-wrap;
}

.meal-picker-search { padding: 8px 20px 0; }

.meal-recipe-list {
  padding: 8px 20px;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 80px;
  max-height: 38vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.meal-recipe-option {
  padding: 14px 16px;
  background: var(--cream-dark); border-radius: var(--radius-sm);
  border: 2px solid transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  transition: all 0.15s;
}
.meal-recipe-option:active { background: var(--green-light); border-color: var(--green); }
.side-dish-selected { background: var(--green-light); border-color: var(--green); }
.btn-side-dish-toggle {
  width: 100%; padding: 12px;
  background: var(--green-light); color: var(--green-dark);
  border: 1.5px solid var(--green);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  text-align: center; transition: opacity 0.15s;
}
.btn-side-dish-toggle:active { opacity: 0.7; }
.modal-back {
  font-size: 18px; font-weight: 700;
  color: var(--text-light); padding: 4px 8px;
  background: none; border: none;
}
.btn-clear-meal {
  padding: 14px 0; border-radius: var(--radius-sm);
  background: var(--yellow-light); color: var(--yellow-dark);
  border: 2px solid var(--yellow);
  font-size: 15px; font-weight: 700;
  transition: opacity 0.15s;
}
.btn-clear-meal:active { opacity: 0.8; }

.meal-option-name { font-size: 15px; font-weight: 600; }
.meal-option-meta { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  left: 50%; transform: translateX(-50%);
  background: rgba(45,42,34,0.92);
  border-radius: 20px;
  padding: 12px 24px;
  font-size: 14px; font-weight: 600;
  color: white;
  z-index: 999;
  white-space: nowrap;
  animation: fadeInUp 0.3s ease;
  pointer-events: none;
  max-width: calc(100vw - 40px);
  text-align: center;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================================================
   Ingredient free-text search row
   ============================================================ */
.ing-search-row {
  display: flex; gap: 8px; align-items: center;
  margin: 0 0 10px;
}
.ing-search-input {
  flex: 1; padding: 9px 14px;
  border: 1.5px solid var(--border); border-radius: 20px;
  background: var(--cream-dark); font-size: 14px;
  font-family: inherit; color: var(--text);
  outline: none; transition: border-color 0.15s;
}
.ing-search-input:focus { border-color: var(--green); background: var(--card); }
.ing-search-input::placeholder { color: var(--text-muted); }
.btn-add-ing-chip {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--green); color: white;
  font-size: 20px; font-weight: 700; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s;
}
.btn-add-ing-chip:active { opacity: 0.7; }
.ing-chip-custom {
  background: var(--yellow-light) !important;
  border-color: var(--yellow) !important;
  color: var(--yellow-dark) !important;
}
.ing-chip-remove {
  font-size: 13px; margin-left: 2px; opacity: 0.7;
}

/* ============================================================
   Recipe Sub-navigation (Find / Browse All)
   ============================================================ */
.recipe-sub-nav {
  display: flex; gap: 0;
  margin: 12px 16px 0;
  background: var(--cream-dark);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.recipe-sub-tab {
  flex: 1; padding: 9px 0;
  border-radius: calc(var(--radius-sm) - 3px);
  font-size: 14px; font-weight: 700;
  color: var(--text-muted);
  background: none;
  transition: all 0.18s;
  text-align: center;
}
.recipe-sub-tab.active {
  background: var(--card);
  color: var(--green-dark);
  box-shadow: 0 1px 6px rgba(80,170,130,0.15);
}

/* Browse All Recipes list */
.browse-recipes-list {
  padding: 8px 16px 100px;
  display: flex; flex-direction: column; gap: 8px;
}
.browse-recipe-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  gap: 12px;
}
.browse-recipe-card:active {
  background: var(--green-light);
  border-color: var(--green);
}
.browse-recipe-name {
  font-size: 15px; font-weight: 700; color: var(--text);
  margin-bottom: 2px;
}
.browse-recipe-meta {
  font-size: 12px; color: var(--text-muted);
}
.browse-edit-icon {
  color: var(--text-muted); flex-shrink: 0; opacity: 0.6;
}

/* ============================================================
   Utilities
   ============================================================ */
.loading {
  text-align: center; padding: 48px 24px;
  color: var(--text-muted);
}
.loading-spinner {
  font-size: 32px; animation: spin 1s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
