.nutrition-overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.nutrition-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.nutrition-metrics > div {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.nutrition-metrics span,
.ingredient-row span,
.ingredient-row small {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.nutrition-metrics strong { display: block; margin-top: 3px; }
/* Meal cards are narrow (three per row): fit as many tiles as the card allows instead of a fixed four, which overflowed the card. */
.nutrition-metrics.compact { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.nutrition-metrics > div { min-width: 0; }
.nutrition-metrics span, .nutrition-metrics strong { overflow-wrap: break-word; }  /* only an unbreakable long word wraps */

.random-recipe {
  display: grid;
  grid-template-columns: minmax(220px, .7fr) minmax(320px, 1.3fr);
  gap: 24px;
  margin-bottom: 20px;
}

.recipe-generator-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.recipe-generator-form .recipe-filters,
.recipe-generator-form .btn,
.nutrition-empty,
.nutrition-disclaimer { grid-column: 1 / -1; }

/* One-time "guideline, not medical advice" acknowledgement shown before the first generated dish. */
.nutrition-disclaimer {
  border: 1px solid var(--warning);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.nutrition-disclaimer h3 { margin: 0 0 8px; }
.nutrition-disclaimer p { margin: 0 0 8px; }

.recipe-filters {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.recipe-filters summary { cursor: pointer; font-weight: 800; }
.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.generated-recipe { margin-bottom: 20px; }
.generated-recipe > header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.ingredient-list { border-top: 1px solid var(--border); }
.ingredient-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.portion-editor,
.ingredient-actions,
.recipe-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.portion-editor .btn { min-width: 42px; padding-inline: 10px; }
.portion-editor .portion-range { flex-basis: 100%; text-align: center; }
.portion-editor > strong { min-width: 52px; text-align: center; }  /* keeps − and + in the same place on every row */
.meal-card-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.clear-list-question { border: 1px solid var(--border, #e5e7eb); border-radius: 12px; padding: 14px 16px; margin: 0 0 16px; }
.clear-list-question p { margin: 0 0 8px; }
/* A target already passed: the amount over it, in the warning colour, instead of a 0 that no longer changes. */
.nutrition-metrics .over-target strong { color: #b45309; }
.share-of-day { margin: 12px 0 0; font-weight: 600; }
.keep-toggle[aria-pressed="true"] { background: var(--primary-soft, #eef2ff); border-color: currentColor; }  /* locked for "Change the Rest" */
.portion-editor .btn:disabled { opacity: .4; cursor: not-allowed; }  /* the portion is at the end of its allowed range */
/* Product code and PDF source: useful for checking the data, so kept one click away rather than on every row. */
.ingredient-details { margin-top: 4px; }
.ingredient-details summary { color: var(--muted); cursor: pointer; font-size: 12px; width: fit-content; }
.recipe-actions { margin-top: 18px; }
.saved-recipe-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.nutrition-empty {
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.nutrition-preferences {
  margin-bottom: 20px;
}

/* Food preferences & safety: a visible card with a summary of what is active, and choice chips while editing. */
.nutrition-preferences { border-left: 4px solid var(--primary); }
.prefs-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.prefs-header h2 { margin: 0 0 4px; }
.prefs-header p { margin: 0; color: var(--muted); }
.prefs-summary { display: grid; gap: 8px; margin: 14px 0 0; }
.prefs-summary div { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.prefs-summary dt { font-weight: 700; min-width: 130px; }
.prefs-summary dd { margin: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.prefs-summary-empty { margin: 12px 0 0; color: var(--muted); }
.chip-static { background: #eef2ff; color: var(--primary); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.prefs-form fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 0; }
.prefs-form legend { font-weight: 700; padding: 0 6px; }
.prefs-form fieldset > .form-note { margin: 0 0 10px; }
.prefs-form fieldset .field { margin-top: 14px; }
.choice-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }  /* still focusable and read by screen readers */
.chip span { display: inline-block; border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; background: var(--surface); font-weight: 600; }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip input:checked + span::before { content: "✓ "; }
.chip input:focus-visible + span { outline: 3px solid #a5b4fc; outline-offset: 2px; }
.excluded-products { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.excluded-products li { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.prefs-form details summary { cursor: pointer; font-weight: 700; }

.nutrition-preferences form,
.meal-allocation {
  display: grid;
  gap: 14px;
}

.nutrition-preferences form {
  margin-top: 18px;
}

.meal-allocation {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.nutrition-preferences fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

/* With the sidebar, three meal cards per row leave each card about 200px wide below 1200px: use two. */
@media (max-width: 1200px) {
  .saved-recipe-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .nutrition-overview, .saved-recipe-list, .random-recipe { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .recipe-generator-form, .filter-grid, .nutrition-metrics {
    grid-template-columns: 1fr 1fr;
  }
  .ingredient-row { grid-template-columns: 1fr; }
  .portion-editor, .ingredient-actions, .recipe-actions { width: 100%; }
  .recipe-actions .btn { flex: 1 1 100%; }
  .meal-allocation { grid-template-columns: 1fr 1fr; }
}

/* Week plan: seven day cards in a wrapping grid, then the cost and the shopping list. */
.week-plan { margin: 20px 0; }
.week-form { display: grid; gap: 12px; margin: 12px 0; }
.week-form fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 0; }
.week-form legend { font-weight: 700; padding: 0 6px; }
/* Seven days: as many columns as fit at about 190 px each (four then three on a laptop, one on a phone). */
.week-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-top: 16px; }
.week-day { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.week-day header { display: flex; justify-content: space-between; align-items: baseline; }
.week-day header span, .week-day footer { color: var(--muted); font-size: 13px; }
.week-day footer { display: grid; gap: 2px; margin-top: auto; border-top: 1px solid var(--border); padding-top: 8px; }
.week-meals { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.week-meals li { display: grid; gap: 4px; }
/* A dish name is a button that opens its recipe. */
.week-meal-name { font: inherit; font-size: 14px; font-weight: 700; text-align: left; overflow-wrap: anywhere; background: none; border: 0; padding: 0;
  color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.week-meal-name:hover, .week-meal-name:focus-visible { text-decoration-thickness: 2px; }
.recipe-window-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); z-index: 1000; display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; overflow-y: auto; }
.recipe-window { width: min(760px, 100%); display: grid; gap: 12px; }
.recipe-window header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.recipe-window h2 { margin: 6px 0 0; }
.week-meal-kcal { color: var(--muted); font-size: 13px; }
.week-meal-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.week-meal-actions .btn { padding: 4px 10px; font-size: 13px; }
.shopping-list { margin-top: 18px; }
.shopping-list summary { cursor: pointer; font-weight: 700; }
.day-cost { font-weight: 700; color: var(--text); }
.week-cost { margin-top: 18px; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.week-cost-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.week-cost-total strong { font-size: 28px; color: var(--primary); }
.week-cost-groups { list-style: none; margin: 10px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.week-cost-groups li { display: flex; gap: 6px; }
.price-source { display: block; color: var(--muted); font-size: 11px; }
.nutrition-jump { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.nutrition-jump .btn { padding: 6px 12px; font-size: 14px; }
/* Nutrition tables (shopping list, recipe ingredients) stay visible on phones and scroll sideways if needed. The app's own
   .table-wrap is hidden on narrow screens, because the exercise tables have a separate phone layout. */
.nutrition-table-wrap { overflow-x: auto; }
.nutrition-table-wrap .exercise-table { min-width: 0; }
.shopping-list .nutrition-table-wrap .exercise-table { min-width: 560px; }
/* A planned meal is clickable as a whole (opens its recipe): show it on hover. */
.week-meal { cursor: pointer; border-radius: 10px; padding: 6px; margin: -6px; }
.week-meal:hover { background: #eef2ff; }

/* Shopping list "Find it at": each supermarket's search for the food (nutrition-ui.js ShopLinks). Wraps inside the cell. */
.shop-links { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.shop-links a { color: var(--primary, #4f46e5); text-decoration: none; white-space: nowrap; }
.shop-links a:hover, .shop-links a:focus-visible { text-decoration: underline; }
