/* === Design Tokens === */
:root {
  --primary:     #4f46e5;
  --primary-d:   #3730a3;
  --accent:      #10b981;
  --danger:      #ef4444;
  --bg:          #0f0f1a;
  --surface:     #1e1e32;
  --surface-2:   #2a2a42;
  --border:      #3a3a56;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --transition:  .18s ease;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; border: none; font: inherit; }
input, select, textarea {
  font: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .55rem .8rem;
  width: 100%;
  transition: border-color var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
textarea { resize: vertical; min-height: 80px; }

/* === Navigation === */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
}
.nav-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-btn {
  background: transparent;
  color: var(--text-muted);
  padding: .4rem .7rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
  transition: color var(--transition), background var(--transition);
}
.nav-btn .nav-icon { font-size: 1.25rem; }
.nav-btn:hover, .nav-btn.active {
  color: var(--primary);
  background: rgba(79,70,229,.12);
}

/* === Main Layout === */
.main {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 5rem;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .5rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .4rem;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .9rem;
  transition: opacity var(--transition), transform var(--transition);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-accent  { background: var(--accent); color: #fff; }
.btn-accent:hover  { opacity: .9; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn-full { width: 100%; }

/* === Tags / Chips === */
.tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tag.selected { background: rgba(79,70,229,.2); border-color: var(--primary); color: var(--primary); }
.tag .tag-remove { cursor: pointer; font-size: 1rem; line-height: 1; }

/* === Category Grid === */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .6rem;
}
.cat-card {
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: .85rem .6rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.cat-card .cat-icon { font-size: 1.8rem; display: block; margin-bottom: .3rem; }
.cat-card .cat-name { font-size: .8rem; font-weight: 500; }
.cat-card.selected { border-color: var(--primary); background: rgba(79,70,229,.12); }

/* === Meal Plan Grid === */
.day-tabs {
  display: flex;
  gap: .4rem;
  overflow-x: auto;
  padding-bottom: .5rem;
  margin-bottom: 1rem;
  scrollbar-width: none;
}
.day-tabs::-webkit-scrollbar { display: none; }
.day-tab {
  flex-shrink: 0;
  padding: .45rem .9rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.day-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.meal-section { margin-bottom: .75rem; }
.meal-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .4rem;
}
.recipe-card {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color var(--transition);
}
.recipe-card:hover { border-color: var(--primary); }
.recipe-card-info { flex: 1; min-width: 0; }
.recipe-card-name { font-weight: 600; font-size: .95rem; margin-bottom: .25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipe-card-meta { font-size: .78rem; color: var(--text-muted); display: flex; gap: .75rem; flex-wrap: wrap; }
.recipe-card-fav { font-size: 1.2rem; padding: .2rem; background: none; border: none; color: var(--text-muted); transition: color var(--transition); }
.recipe-card-fav.active { color: #f59e0b; }

/* === Nutrition Bar === */
.nutrition {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .5rem;
}
.nutr-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .25rem .6rem;
  font-size: .78rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.nutr-badge span:first-child { font-weight: 700; font-size: .95rem; }
.nutr-badge span:last-child { color: var(--text-muted); }

/* === Shopping List === */
.shop-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  margin-bottom: .4rem;
  transition: opacity var(--transition);
}
.shop-item.checked { opacity: .45; }
.shop-item input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.shop-item-name { flex: 1; font-size: .9rem; }
.shop-item-qty { font-size: .82rem; color: var(--text-muted); white-space: nowrap; }
.shop-item-pantry { font-size: .7rem; color: var(--accent); font-weight: 600; }

/* === Form Groups === */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .4rem; color: var(--text-muted); }
.input-row { display: flex; gap: .5rem; }
.input-row input { flex: 1; }

/* === Tag List === */
.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }

/* === Loading === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,15,26,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-text { color: var(--text-muted); font-size: .95rem; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === Modal === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 1.5rem;
  animation: slide-up .2s ease;
}
@keyframes slide-up { from { transform: translateY(60px); opacity: 0; } }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .5rem;
}
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-close { background: none; color: var(--text-muted); font-size: 1.4rem; line-height: 1; padding: .2rem; }

/* === Toast === */
.toast-container { position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%); z-index: 500; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .55rem 1.2rem;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  animation: fade-in .2s ease;
}
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error   { border-color: var(--danger);  color: var(--danger); }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } }

/* === Section Headers === */
.section-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 1.25rem; }
.section-sub { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; margin-top: -.75rem; }

/* === Ingredient List === */
.ing-list { list-style: none; }
.ing-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.ing-list li:last-child { border-bottom: none; }
.ing-qty { color: var(--text-muted); font-size: .82rem; margin-left: auto; }

/* === Step List === */
.step-list { counter-reset: steps; list-style: none; }
.step-list li {
  counter-increment: steps;
  display: flex;
  gap: .75rem;
  margin-bottom: .85rem;
  font-size: .9rem;
  line-height: 1.5;
}
.step-list li::before {
  content: counter(steps);
  min-width: 24px;
  height: 24px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: .1rem;
}

/* === Batch Tip Box === */
.batch-tip {
  background: rgba(16,185,129,.1);
  border: 1px solid rgba(16,185,129,.3);
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
  font-size: .88rem;
  color: var(--accent);
  margin-top: .75rem;
  display: flex;
  gap: .5rem;
}

/* === History List === */
.history-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 1rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color var(--transition);
}
.history-item:hover { border-color: var(--primary); }
.history-date { font-size: .8rem; color: var(--text-muted); }

/* === Settings === */
.settings-section { margin-bottom: 1.5rem; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { flex: 1; font-size: .92rem; }
.settings-row select { max-width: 140px; }

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state p { font-size: .95rem; }

/* === Responsive === */
@media (min-width: 600px) {
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .modal { border-radius: var(--radius); }
  .modal-backdrop { align-items: center; }
}
