/*
 * Meals: the saved meals as entry rows, searchable once there are a few,
 * and the meal form.
 */
@layer components {
  .meal-library__search { margin-bottom: var(--space-3); }

  /* A section heading with its controls on the same line. */
  .section-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    margin-bottom: var(--space-3);
  }
  .section-bar h2 { font-size: var(--text-xl); }

  /* Two or three choices, one current: a pill split in parts. */
  .segmented {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius-pill);
    background: var(--surface);
  }
  .segmented__option {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding-inline: var(--space-4);
    border-radius: var(--radius-pill);
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 800;
    text-decoration: none;
  }
  .segmented__option:hover { color: var(--ink); }
  .segmented__option[aria-current="page"], .segmented__option[aria-pressed="true"] { background: var(--leaf); color: var(--cream); }
  button.segmented__option { border: 0; background: none; font-family: inherit; cursor: pointer; }

  .entry-list__empty {
    padding: var(--space-5);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-lg);
    color: var(--muted);
    font-weight: 600;
    text-align: center;
  }
  .entry-list__note { margin: var(--space-3) var(--space-2) 0; color: var(--muted); font-size: var(--text-sm); font-weight: 600; }

  a.entry__summary { color: inherit; text-decoration: none; }

  .input--number { max-width: 7rem; }
  .inline-form__row .input--number { flex: 0 0 7rem; }
  .input--area { min-height: 0; padding-block: var(--space-3); border-radius: var(--radius-md); resize: vertical; }

  /* The ingredient lines of a meal, group or list entry form: item, how much,
     how it counts, remove. On a phone the item takes the row beside remove,
     with how much and how it counts under it. */
  .ingredients { min-width: 0; margin: 0; padding: 0; border: 0; }
  .ingredients__list { display: grid; gap: var(--space-2); margin-top: var(--space-2); }
  .ingredient-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 6.5rem 7rem var(--touch);
    grid-template-areas: "name amount counting remove";
    align-items: center;
    gap: var(--space-2);
  }
  .ingredient-row > .item-combobox { grid-area: name; min-width: 0; }
  .ingredient-row__amount-field { grid-area: amount; min-width: 0; }
  .ingredient-row__counting { grid-area: counting; padding-inline: var(--space-3); }
  .ingredient-row > .ingredient-row__remove { grid-area: remove; }
  .ingredient-row__caption { display: none; }
  .ingredient-row[hidden] { display: none; }
  @media (max-width: 559px) {
    .ingredients__head { display: none !important; }
    .ingredients__list { gap: 0; }
    .ingredient-row {
      grid-template-columns: minmax(0, 1fr) var(--touch);
      grid-template-areas: "name remove" "amount amount" "counting counting";
      gap: var(--space-1) var(--space-2);
      padding-block: var(--space-3);
    }
    .ingredient-row + .ingredient-row { border-top: 1px solid var(--line); }
    .ingredient-row__amount-field { display: grid; gap: 2px; justify-self: start; width: 8rem; }
    .ingredient-row__caption { display: block; color: var(--muted); font-size: var(--text-xs); font-weight: 800; }
    .ingredient-row__counting { justify-self: start; width: auto; }
  }

  /* A group or meal included whole: what kind and remove, then what, times and its label, and a way to see it. */
  .ingredient-row.ingredient-row--nested {
    grid-template-columns: 4.75rem minmax(0, 1fr) var(--touch);
    grid-template-areas: "kind kind remove" "times nested nested" ". label label" ". edit edit";
    padding: var(--space-2);
    margin-inline: calc(-1 * var(--space-2));
    border-radius: var(--radius-md);
    background: var(--mint-soft);
  }
  /* Placed, not flowed: a group's only line hides its remove button, which would pull these up a row. */
  .ingredient-row__kind { grid-area: kind; color: var(--leaf); font-size: var(--text-xs); font-weight: 800; }
  .ingredient-row--nested .ingredient-row__times { grid-area: times; }
  .ingredient-row--nested .ingredient-row__nested { grid-area: nested; min-width: 0; }
  .ingredient-row--nested .ingredient-row__label { grid-area: label; }
  .ingredient-row--nested .ingredient-row__edit { grid-area: edit; }
  @media (max-width: 559px) {
    .ingredient-row.ingredient-row--nested {
      grid-template-columns: 4.75rem minmax(0, 1fr) var(--touch);
      grid-template-areas: "kind kind remove" "nested nested nested" "times label label" "edit edit edit";
      margin-block: var(--space-2);
    }
    .ingredient-row + .ingredient-row--nested,
    .ingredient-row--nested + .ingredient-row { border-top: 0; }
  }
  .ingredient-row__times { display: flex; align-items: center; gap: var(--space-1); color: var(--muted); font-weight: 800; }
  .ingredient-row__times .input { min-width: 0; }
  .ingredients__group { margin: var(--space-2) 0 0; color: var(--muted); font-size: var(--text-sm); font-weight: 800; }
  .ingredients__group:first-child { margin-top: 0; }
  .ingredient-row__edit { justify-self: start; color: var(--leaf); font-size: var(--text-sm); font-weight: 800; }
  .ingredients__head { display: grid; grid-template-columns: minmax(0, 1fr) 6.5rem 7rem var(--touch); gap: var(--space-2); margin-top: var(--space-2); color: var(--muted); font-size: var(--text-xs); font-weight: 800; }
  .ingredients__head + .ingredients__list { margin-top: var(--space-1); }
  .ingredient-row__error { grid-column: 1 / -1; }
  .ingredient-row__new-item { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: 800; cursor: pointer; }
  .ingredient-row__new-item input { width: 20px; height: 20px; accent-color: var(--leaf); }
  .ingredient-row__remove {
    width: var(--touch);
    height: var(--touch);
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
  }
  .ingredient-row__remove:hover { background: var(--danger-soft); color: var(--ink); }
  .ingredients .button--quiet svg { width: 18px; height: 18px; }

  /* A checkbox with a label and a hint beside it. */
  .check-field { display: flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; }
  .check-field__box { flex: none; width: 22px; height: 22px; margin-top: 2px; accent-color: var(--leaf); }
  .check-field__label { display: block; font-size: var(--text-sm); font-weight: 800; }

  .meal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }
}
